Python - class private publc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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