Last active
September 15, 2018 19:45
-
-
Save pknowledge/bb2016b365ed9b20bd3b9b0d6c273cfd to your computer and use it in GitHub Desktop.
public_and_private_members.py
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 Hello: | |
def __init__(self, name): | |
self.public_variable = 10 | |
self.__private_variable = 30 | |
def public_method(self): | |
print(self.public_variable) | |
print(self.__private_variable) | |
print('public') | |
self.__private_method() | |
def __private_method(self): | |
print('private') | |
hello = Hello('name') | |
print(hello.public_variable) | |
hello.public_method() | |
#print(hello.__private_variable) # not allowed outsite the class | |
#hello.__private_method # not allowed outsite the class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment