Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python - class private publc
class Person:
def __init__(self):
def _single(self):
print "single"
def __double(self):
print "double"
p = Person()
print(dir(p)) # ['_Person__double', '__doc__', '__init__', '__module__', '_single']
p._single() # single
p._Person__double() # double
p.__double() # AttributeError: Person instance has no attribute '__double'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment