37. Singleton Pattern
The Singleton pattern ensures only one instance of a class exists.
Example
class Singleton:
_instance = None
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super().__new__(cls)
return cls._instance
a = Singleton()
b = Singleton()
print(a is b) # True
Wrap-Up
Singleton ensures a single shared instance, useful for configurations or logging.