+ 2

Difference between normal functions and 'magic methods' in python?

I am confused about the inbuilt methods and magic methods in python. I just noticed that in magic methods we use double underscore in both ends.

27th Jan 2017, 7:47 AM
Pranjith P
Pranjith P - avatar
2 Respostas
0
Hi Pranjith, "magic methods" or "dundre methods" are just methods like any others... but they have a "special name" and are called with a "special format". In the name, they have a double underscore in both side (__add__ , __init__). And when you call they, will use the special format, so "__add__" will be "+", and "__sub__" will be "-"...
30th Mar 2017, 12:50 PM
Rodrigo Faria
Rodrigo Faria - avatar