Created
April 4, 2022 06:54
-
-
Save saratrajput/18d213b0610d0d9370c9c856c58e16f4 to your computer and use it in GitHub Desktop.
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
# 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