0
init method in python 3
my question is that: Is it mandatory to always type underscore twice while writing init method(like __init__)? Is that only the syntax?
3 ответов
+ 1
It is necessary because Python treats some methods with underecores differently so there aren't name conflicts with special methods and normal ones.
+ 1
There are special method names to define what happens when you use built-in operators or functions on your object/class, and they start and end with two underscores.
Examples:
obj1 = MyClass() __init__
obj1 + obj2 __add__
del (obj2) __del__
... and so on.
https://www.python-course.eu/python3_magic_methods.php
+ 1
Got it👍Thanks!