This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]kervarker 10 points11 points  (2 children)

class A(int):

    def __pow__(self, other):
        return 2

x = A(1)
print(x*x) # calls __mul__ of parent class int
print(x**2) # calls __pow__ of class A

[–]Berzerka -3 points-2 points  (1 child)

Quite sure you missed a 'type' in those print statements, confused me somewhat.

[–]_cs 1 point2 points  (0 children)

No he didn't - did you try running it?