4 ms·
Double underscore is the real 'private': >>> class Foo: def __fn(self): return 2 >>> Foo().__fn() Traceback (most recen
by ben-schaaf 8y ago
Double underscore is the real 'private':
>>> class Foo:
def __fn(self):
return 2
>>> Foo().__fn()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Foo' object has no attribute '__fn'
>>> Foo()._Foo__fn()
2
A single underscore is more like 'protected', ie. it doesn't prevent subclasses from easily/accidentally overriding your function.