Skip to content

Instantly share code, notes, and snippets.

@qgp9
Last active July 25, 2016 07:58
Show Gist options
  • Select an option

  • Save qgp9/99181e9fdb3efcc260f2b50fabc2aafa to your computer and use it in GitHub Desktop.

Select an option

Save qgp9/99181e9fdb3efcc260f2b50fabc2aafa to your computer and use it in GitHub Desktop.
python private/protected method test
# python private/protected method test
class MyClass:
def __init__(self):
self.publicMember1 = "Public Member"
self._privateMember1 = "Private Member"
self.__protectedMember1 = "Protected Member"
def printPublic(self):
print ("This is Public Method")
def _printPrivate(self):
print ("This is Private Method")
def __printProtected(self):
print ("This is Protected Method")
myObj = MyClass()
myObj.printPublic()
myObj._printPrivate()
myObj._MyClass__printProtected()
print( myObj.publicMember1 )
print( myObj._privateMember1 )
print( myObj._MyClass__protectedMember1 )
This is Public Method
This is Private Method
This is Protected Method
Public Member
Private Member
Protected Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment