69. Callable Objects
1. Basic Callable Object
class CallableClass:
def __call__(self, *args, **kwargs):
return "Hello from __call__!"
obj = CallableClass()
print(obj()) # Output: Hello from __call__!2. Callable Object with Arguments
class Adder:
def __call__(self, a, b):
return a + b
add = Adder()
result = add(5, 3)
print(result) # Output: 83. Callable Object with Dynamic Behavior
4. Callable Object with Return Value
5. Callable Object for Sorting
6. Callable Object with Internal State Update
7. Callable Object with Keyword Arguments
8. Callable Object for Function Composition
9. Callable Object with Default Parameters
10. Callable Object with Logging
Last updated