- global variable
Example:
x = "global"
def foo():
global x
y = "local"
x = x * 2
print(x)
print(y)
foo()
- __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.
class MyClass(object):
i = 123
def __init__(self):
self.i = 345
a = MyClass()
print(a.i)
print(MyClass.i)