Python utilities


Key information of the python strcutures are discussed here.

  1. global variable
  2. Example: 
    x = "global"
    def foo():
        global x
        y = "local"
        x = x * 2
        print(x)
        print(y)
        
    foo()
    
  3. __init__ and __self__: __init__ does act like a constructor. You'll need to pass "self" to any class functions as the first argument if you want them to behave as non-static methods. "self" are instance variables for your class.
  4. class MyClass(object):
        i = 123
        def __init__(self):
            self.i = 345
    
    a = MyClass()
    print(a.i)
    print(MyClass.i)