What is dunders in programming world? What it's used? | SoloLearn: Learn to code for FREE!


What is dunders in programming world? What it's used?

10/15/2019 9:14:00 PM

Prince Raj

5 Answers

New Answer


Pythonist do call the double underscores "Dunder". For example __baz__ = "hello" You can call this "dunder baz" instead of " double underscore baz". Also, methods with dunder in python are reffered to as the magic method, (i don't really know why) cos there's nothing magical in what they do


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


Mirielle🐶 thanks for the useful info. I had no idea.


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)


Here’s an example of how magic methods are used for operator overloading in Python. https://code.sololearn.com/c54jn2y004wp/?ref=app