Name of Python actually comes from the show Monty Python
Python execute from top to bottom in order. Variables have function-leveled scope, so defined variables are good to use until the function ends.
Method conventions:
class Example:
def public_method(self): ...
def _protected_method(self): ...
def __private_method(self): ...
But those are just naming conventions, and Python would allow you to call any of them outside of class.
Every object in python is allocated in the heap, and they are referenced. In fact, all variables in python are object references.
A class method is a method that has no self parameters, so they can’t access member variables. They follow the class itself but not the instances. Just like static
functions in java
Python’s destructor is implemented under the __del__
function. It is not guaranteed to be called right away since it would be called when it’s being garbage collected. Python would use a reference count to determine when to be garbage collected.
Python passes parameter by object reference which is identical to pass by pointer in C++
Script is a .py
file that implements a main function and is mean tot run as a stand alone program, while modules mainly provides functions to other scripts/modules.
Trivial fact:
+=
operator to python list is a syntax sugar for.append
, and if one doeslst = l1 + l2
, this will create a new list