What is a magic method __other__ in this code?What this method doing? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 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)

1st Aug 2022, 10:34 PM
Yar
Yar - avatar
4 ответов
+ 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
2nd Aug 2022, 9:39 AM
Lothar
Lothar - avatar
2nd Aug 2022, 12:29 AM
Ipang
+ 1
Thanks
2nd Aug 2022, 3:11 AM
Yar
Yar - avatar
+ 1
Thank you
2nd Aug 2022, 11:33 AM
Yar
Yar - avatar