Code: Select all
In [1]: class TestSingleUnderscore(object):
...: def _init_(self):
...: self.x = 1
...:
In [2]: class TestDoubleUnderscore(object):
...: def __init__(self):
...: self.x = 1
...:
In [3]: single = TestSingleUnderscore()
In [4]: double = TestDoubleUnderscore()
In [5]: single.x
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-6a93332d6ce4> in <module>()
----> 1 single.x
AttributeError: 'TestSingleUnderscore' object has no attribute 'x'
In [6]: double.x
Out[6]: 1