+ 1
Why and how does it work?
Why and how does the empty class work? class A(int): pass print(A(9) + A(9)) #output 18 The operator + is not overloaded. Moreover, there isn't anything that stores the int passed in.
4 odpowiedzi
+ 3
Because A(int) means A is now a class and its parent class is int. Meaning that class A can do anything an int can do, add, subtract, or any other operation as well.
+ 1
Slick int is a class? What about the other primitive types like string and float?
+ 1
Yes, a class. Because remember, in python, EVERYTHING is an object. Strings and floats as well
+ 1
Thank you!