Skip to content

Instantly share code, notes, and snippets.

@syedjafer
Created September 7, 2022 15:43
Show Gist options
  • Save syedjafer/2f9499f95f70275b17ef8336c9e0677e to your computer and use it in GitHub Desktop.
Save syedjafer/2f9499f95f70275b17ef8336c9e0677e to your computer and use it in GitHub Desktop.
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