![]() | Special methods have leading and trailing double underscores (e.g. __str__) |
![]() | Here are some operations defined by special methods:
len(a) # a.__len__() c = a*b # c = a.__mul__(b) a = a+b # a = a.__add__(b) a += c # a.__iadd__(c) d = a[3] # d = a.__getitem__(3) a[3] = 0 # a.__setitem__(3, 0) f = a(1.2, True) # f = a.__call__(1.2, True) if a: # if a.__len__()>0: or if a.__nonzero(): |