Skip to content

Instantly share code, notes, and snippets.

@PramodDutta
Created September 5, 2024 01:24
Show Gist options
  • Save PramodDutta/7b1c9b3b07a273188fd766205f6731ee to your computer and use it in GitHub Desktop.
Save PramodDutta/7b1c9b3b07a273188fd766205f6731ee to your computer and use it in GitHub Desktop.
EncapsulationExample
class MyClass:
# Public variable
public_var = "I am public."
# Protected variable
_protected_var = "I am protected."
# Private variable
__private_var = "I am private."
def __init__(self):
# Accessing public variable
print(self.public_var)
# Accessing protected variable
print(self._protected_var)
# Accessing private variable
print(self.__private_var)
# Creating an instance of the class
obj = MyClass()
print(obj.public_var)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment