1class Cud(): 2 3 def __init__(self): 4 print("__init__ called") 5 6 def __repr__(self): 7 print("__repr__ called") 8 return "" 9 10 def __lt__(self, other): 11 print("__lt__ called") 12 13 def __le__(self, other): 14 print("__le__ called") 15 16 def __eq__(self, other): 17 print("__eq__ called") 18 19 def __ne__(self, other): 20 print("__ne__ called") 21 22 def __ge__(self, other): 23 print("__ge__ called") 24 25 def __gt__(self, other): 26 print("__gt__ called") 27 28 def __abs__(self): 29 print("__abs__ called") 30 31 def __add__(self, other): 32 print("__add__ called") 33 34 def __and__(self, other): 35 print("__and__ called") 36 37 def __floordiv__(self, other): 38 print("__floordiv__ called") 39 40 def __index__(self, other): 41 print("__index__ called") 42 43 def __inv__(self): 44 print("__inv__ called") 45 46 def __invert__(self): 47 print("__invert__ called") 48 49 def __lshift__(self, val): 50 print("__lshift__ called") 51 52 def __mod__(self, val): 53 print("__mod__ called") 54 55 def __mul__(self, other): 56 print("__mul__ called") 57 58 def __matmul__(self, other): 59 print("__matmul__ called") 60 61 def __neg__(self): 62 print("__neg__ called") 63 64 def __or__(self, other): 65 print("__or__ called") 66 67 def __pos__(self): 68 print("__pos__ called") 69 70 def __pow__(self, val): 71 print("__pow__ called") 72 73 def __rshift__(self, val): 74 print("__rshift__ called") 75 76 def __sub__(self, other): 77 print("__sub__ called") 78 79 def __truediv__(self, other): 80 print("__truediv__ called") 81 82 def __div__(self, other): 83 print("__div__ called") 84 85 def __xor__(self, other): 86 print("__xor__ called") 87 88 def __iadd__(self, other): 89 print("__iadd__ called") 90 return self 91 92 def __isub__(self, other): 93 print("__isub__ called") 94 return self 95 96 def __int__(self): 97 return 42 98 99cud1 = Cud() 100cud2 = Cud() 101 102str(cud1) 103cud1 == cud1 104cud1 == cud2 105cud1 != cud1 106cud1 != cud2 107cud1 < cud2 108cud1 <= cud2 109cud1 == cud2 110cud1 >= cud2 111cud1 > cud2 112cud1 + cud2 113cud1 - cud2 114print(int(cud1)) 115 116class BadInt: 117 def __int__(self): 118 print("__int__ called") 119 return None 120 121try: 122 int(BadInt()) 123except TypeError: 124 print("TypeError") 125 126# more in special_methods2.py 127