Skip to content

Instantly share code, notes, and snippets.

@pknowledge
Last active September 15, 2018 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pknowledge/bb2016b365ed9b20bd3b9b0d6c273cfd to your computer and use it in GitHub Desktop.
Save pknowledge/bb2016b365ed9b20bd3b9b0d6c273cfd to your computer and use it in GitHub Desktop.
public_and_private_members.py
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