Skip to content

Instantly share code, notes, and snippets.

@hanksudo
Created October 8, 2017 16:17
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Python - class private publc
class Person:
def __init__(self):
pass
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