Skip to main content

Python deeper

 

Everything is an Object

https://www.i-programmer.info/programming/python/11683-programmers-python-variables-objects-and-attributes.html

https://www.edureka.co/blog/interview-questions/python-interview-questions/

namespaces are variable names.

variables and functions are objects in python

objects are instance of a class

functions are first class objects - meaning they are objects like int, float, bool, list, string etc., they can be passed as arguments, assigned to a variable, returned from a function, etc. - https://www.youtube.com/watch?v=p8RU0JH2xb8

"When one says "everything is an object" (like in Python), does he indeed mean that "everything is first-class"?" : Yes - “First class” means you can operate on them in the usual manner. Most of the times, this just means you can pass these first-class citizens as arguments to functions, or return them from functions.
https://stackoverflow.com/questions/245192

Python Variable Scope –Built-in, Global,  Enclosed,  Local, 

a = 1
def sample():
    b = 2
    def sample1():
            global a # if we want to change the value of global variable
            nonlocal b # if we want to change the value of enclosed variable
            c = 3
 
a is global, b is encolsed, c is local
The built-in scope has all the names that are loaded into python variable scope when we start the interpreter. For example, we never need to import any module to access functions like print() and id().

id() : If we relate this to C, then they are actually the memory address, here in Python it is the unique id.
https://www.geeksforgeeks.org/id-function-python

Decorators in python: https://www.programiz.com/python-programming/decorator



def no_of_argu(*args):
     
    # using len() method in args to count
    return(len(args))




Built-in datatypes: 
    Numbers - int, float, complex, ex: 1, 1.4, 3+4i
    List
    Tuple
    String
    Set
    Dictionary
    Boolean

.pyc files contain the bytecode of the python files. .pyc files are created when the code is imported from some other source. The interpreter converts the source .py files to .pyc files which helps by saving time.