Last active
July 25, 2016 07:58
-
-
Save qgp9/99181e9fdb3efcc260f2b50fabc2aafa to your computer and use it in GitHub Desktop.
python private/protected method test
This file contains hidden or 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
| # 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 file contains hidden or 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
| 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