+ 1
What is a magic method __other__ in this code?What this method doing?
class Vector2D: def __init__(self, x, y): self.x = x self.y = y def __add__(self, other): return Vector2D(self.x+other.x, self.y+other.y) first=Vector2D(5, 7) second=Vector2D(3, 4) result=first+second print(result)
4 Antworten
+ 3
Yar ,
`other` is a parameter name that is used by some `magic` methods, but we can also use whatever valid identifier name.
here is a link that gives some more and specific information:
https://stackoverflow.com/questions/51010228/what-does-other-mean-in-JUMP_LINK__&&__python__&&__JUMP_LINK
+ 2
This page might help you understand ...
https://www.tutorialsteacher.com/JUMP_LINK__&&__python__&&__JUMP_LINK/magic-methods-in-python
+ 1
Thanks
+ 1
Thank you