See https://stackoverflow.com/questions/3972872/python-variables-as-keys-to-dict
dict {'a' : method1(),
'b' : method2()}
#Invokes method1()
dict['a']
Add-On
Dictionaries can also be iterated with a default value using get
dict.get('c', print "This variable does not exist - please debug")
Inheriting a class Parent is the parent class that inherits all variables and methods:
class toInherit(Parent):
def method1():
pass
Overriding Methods You can override methods just by using the same function name as the parent class
Static Methods Inserting the @staticmethod property on top of a class makes it callable (Cannot be called within the same class) Use Class.method inorder to do recurstion here
class math():
@staticmethod
def method1(var1, var2):
return var + var2
{Un}Packing Varables Functions can be packed:
def method1(var1, var2):
return var + var2
numbers = [1, 5]
print method1(*numbers)
>>> 6
Functions can also be unpacked
def method1(*many_numbers):
return sum(many_numbers)
numbers = [1, 5, 2, 2, 1, 2]
print method1(numbers)
>>> 13