0
what is magic methods in python?
came across this word and wondering what it is to try.
3 odpowiedzi
+ 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
+ 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.
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