Created
October 8, 2017 16:17
-
-
Save hanksudo/665dd3e24216068efae2f480fd6b56ac to your computer and use it in GitHub Desktop.
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