+ 2
What is dunders in programming world? What it's used?
5 Answers
+ 9
If i should add this.
They are called magic methods because they mostly used for operator overloading without explicit conversion.
P.S: probably nothing magical true or perhaps coz they can be confusing
+ 5
Mirielleđ¶ thanks for the useful info. I had no idea.
+ 2
simple example/explanation..
imagine you had a class rectangle with an appropriate constructor...so
rect1 = rectangle(10, 20)
rect2 = rectangle(30, 40).
You could define a dunder to do:-
rect3 = rect1 + rect2.
(it is explained in the python tutorial)
+ 2
Hereâs an example of how magic methods are used for operator overloading in Python.
https://code.sololearn.com/c54jn2y004wp/?ref=app