Ad

A class that can be called.

class greeting:
    def __init__(self, name: str, formal: bool = False):
        self.name = name
        self.formal = formal
        
    def __call__(self) -> str:
        if self.formal: return f'Hello, Sir {self.name}.'
        else: return f'Hello, {self.name}!'
    
g1 = greeting('John')
g2 = greeting('Churchill', True)

print(g1()) # 'Hello, John!'
print(g2()) # 'Hello, Sir Churchill.'