Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saratrajput/18d213b0610d0d9370c9c856c58e16f4 to your computer and use it in GitHub Desktop.
Save saratrajput/18d213b0610d0d9370c9c856c58e16f4 to your computer and use it in GitHub Desktop.
# Single underscore
class Example():
_private_variable = 10
def __init__(self):
self._private_variable = 20
example_object = Example()
print(example_object._private_variable)
# Double underscores
class Example():
__private_variable = 10
def __init__(self):
self.__private_variable = 20
example_object = Example()
# You can still access the private variable but it is 'discouraged'
print(example_object._Example__private_variable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment