Created
September 7, 2022 15:43
-
-
Save syedjafer/2f9499f95f70275b17ef8336c9e0677e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 SingleTon: | |
# Creating a static private variable | |
_instance = None | |
# __new__ is called inside __init__ for object instantiation. | |
def __new__(self): | |
if( not self._instance ): | |
self._instance = super(SingleTon, self).__new__(self) | |
self.y = 10 | |
return self._instance | |
obj1 = SingleTon() | |
print(obj1.y) | |
obj1.y = 30 | |
obj2 = SingleTon() | |
print(obj2.y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment