I tried the following:
[color=blue][color=green][color=darkred]
>>> x = complex(4)
>>> y = x
>>> y *= 2
>>> print x, y[/color][/color][/color]
(4+0j) (8+0j)
But when I tried the same thing with my own class in place of
"complex" above, I found that both x and y were doubled. I'd like to
make my class behave like the "complex" class. Can someone tell me the
trick? Also, where can I find the code for for the "complex" class? I
hope it's written in Python! Thanks.
[color=blue][color=green][color=darkred]
>>> x = complex(4)
>>> y = x
>>> y *= 2
>>> print x, y[/color][/color][/color]
(4+0j) (8+0j)
But when I tried the same thing with my own class in place of
"complex" above, I found that both x and y were doubled. I'd like to
make my class behave like the "complex" class. Can someone tell me the
trick? Also, where can I find the code for for the "complex" class? I
hope it's written in Python! Thanks.
Comment