in Python 2.7 one can created private members of a class by preceding them with '__'
>>> class Test:
def __f():
print 'hi'
>>> ob=Test()
>>> ob.__f()
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
ob.__f()
AttributeError: Test instance has no attribute '__f'
In python one can define a function like f__(x)
also. Then why isn't a function defined as
__f__(x)
not treated private?
>>> class Test2:
def __f__(self):
print 'hi'
>>> ob2=Test2()
>>> ob2.__f__()
hi
So how exactly are __f__()
different from f()?