Is there some difference between functions defined in python as
__func__()
and func()
.
What is the use of adding underscores in front and back ?
Asked
Active
Viewed 101 times
0

Eric Shelhamer
- 85
- 1
- 8
-
double underscore on both front and back is mainly used to indicate [magic methods](http://www.rafekettler.com/magicmethods.html) , I would suggest not to use them for user defined functions/methods (to avoid confusion) . – Anand S Kumar Sep 19 '15 at 04:51
-
They aren't magic functions but are used in classes so as to provide better help like __init__ function initializes a.class, __str__ is for string representation, __cmp__ to compare, etc. – Sep 19 '15 at 08:18