I am unable to understand Dunders Methods.Why there is need for using this? If we can do this with below way
class abc:
a=9
b=10
print(a+b)
output: 19
I am unable to understand Dunders Methods.Why there is need for using this? If we can do this with below way
class abc:
a=9
b=10
print(a+b)
output: 19
hey @LPLC0090,
Dunder methods or magic functions , they are same thing , are nothing as such particular but simple functions , the same we declare normally. But just the difference they are such functions which are defined by the default for classes , such as __init__
, __add__
,__repr__
, etc.
They define some default functioning of class objects.
For such simple tasks, as you stated above , there is no need. But they do help in cases where there is a proper help or usage needed of classes and there objects various times in codes with various operations.
I hope this helped you understand it.
Thank You ,