while defining method,what is the difference in
this:
def init(...........):
................................
and
this:
def _init_(............):
................................
In that case, it's just a different name. But __init__ (note the double underscores on both sides, or "dunder") is called automatically when you create an object.
Output:
>>> class Manual:
def init(self):
self.x = None
>>> m = Manual()
>>> print m.x
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
print m.x
AttributeError: Manual instance has no attribute 'x'
>>> m.init()
>>> print m.x
None
>>> class Automatic:
def __init__(self):
self.x = None
>>> a = Automatic()
>>> print a.x
None