what is magic methods in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is magic methods in python?

came across this word and wondering what it is to try.

23rd Feb 2017, 8:33 PM
Bala Krishnan Swaminathan Mani
Bala Krishnan Swaminathan Mani - avatar
3 Answers
+ 1
Python magic methods are built into the language. They are methods that you don't usually call directly, but are invoked behind the scenes. They begin and end with a double underscore or "dunder" as they are often referred to. Although they are reserved for the python language, most can be overridden or overloaded. You can not create your own magic methods, but you can create methods that use the dunderMethodNamedunder naming style, however this is greatly frowned upon and discouraged. Some examples would be: __init__(self, ...) __str__(self) __repr__(self) __name__ __main__ More info: http://www.python-course.eu/python3_magic_methods.php
23rd Feb 2017, 11:57 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
I believe that he refereed from the question What magic method make a new instance. I'm holding in this question. I try a lot of answer, but all was wrong.
25th Mar 2017, 2:51 PM
Juan Luis Jiménez Teruel
Juan Luis Jiménez Teruel - avatar
0
They are built-in function that a specific software has. Not all compiler has the same magic methods. for example in jupyter you have: %matplotlib inline
23rd Feb 2017, 8:56 PM
basusu