Last modified: Feb 11, 2026 By Alexander Williams
Python Callable Objects: Functions and Classes
In Python, many things are objects. Some objects can be "called" like a function. These are callable objects.
Knowing what is callable is a core Python skill. It helps you write flexible and powerful code.
What is a Callable Object?
A callable object is anything you can invoke with parentheses. You can pass arguments to it.
The most common callables are functions and methods. But classes and certain class instances are also callable.
You can check if an object is callable using the built-in callable() function. It returns True or False.
# Checking various objects with callable()
print(callable(print)) # The print function
print(callable(len)) # The len function
print(callable("hello")) # A string
print(callable(42)) # An integer
True
True
False
False
The output shows functions are callable. Basic data types like strings and integers are not.
Common Types of Callable Objects
Python has several built-in types of callables. Understanding them is key.
1. Built-in Functions and User-Defined Functions
Functions are the simplest callables. Python provides many built-in functions like print(), len(), and str().
Functions you define with def are also callable objects.
def greet(name):
"""A simple user-defined function."""
return f"Hello, {name}!"
# Both are callable
print(callable(greet)) # Check our function
print(callable(abs)) # Check built-in abs()
# Call them
print(greet("Alice"))
print(abs(-10))
True
True
Hello, Alice!
10
2. Classes are Callable
In Python, a class is a callable object. Calling a class creates a new instance of that class.
This process is called instantiation. The class's __init__ method runs during this call. For a deeper dive into how classes and instances work, see our Python Objects: Classes, Instances, and Methods Guide.
class Dog:
def __init__(self, name):
self.name = name
print(f"{name} is born!")
# The class Dog is callable
print(callable(Dog))
# Calling the class creates an instance
my_pet = Dog("Rex")
True
Rex is born!
3. Methods
Methods are functions defined inside a class. They are bound to an instance or the class itself.
Instance methods, class methods, and static methods are all callable objects.
class Calculator:
def instance_method(self, x):
return x * 2
@classmethod
def class_method(cls):
return "Class method called"
@staticmethod
def static_method():
return "Static method called"
calc = Calculator()
# All are callable
print(callable(calc.instance_method))
print(callable(Calculator.class_method))
print(callable(Calculator.static_method))
# Call them
print(calc.instance_method(5))
print(Calculator.class_method())
print(Calculator.static_method())
True
True
True
10
Class method called
Static method called
The __call__ Method: Making Instances Callable
This is a powerful feature. You can make your own class instances act like functions.
Define a __call__ method inside your class. Then, you can use parentheses on instances.
Objects with a __call__ method are known as functors or callable instances.
class Multiplier:
def __init__(self, factor):
# Store the factor as an instance attribute
self.factor = factor
def __call__(self, number):
# This makes the instance callable
return number * self.factor
# Create an instance
times_three = Multiplier(3)
# Check if it's callable
print(callable(times_three)) # True!
# Use it like a function
result = times_three(10)
print(f"10 multiplied by 3 is {result}")
# Create another with a different state
times_five = Multiplier(5)
print(times_five(10))
True
10 multiplied by 3 is 30
50
The instance times_three remembers its state (self.factor = 3). This is very useful.
It combines the data storage of an object with the behavior of a function. Understanding Python object attributes is crucial for managing this state effectively.
Practical Use Cases for Callable Objects
Why would you use this? Callable instances are great for creating configurable, stateful operations.
1. Creating Function-like Objects with Memory
They can remember information between calls. This is simpler than using global variables.
class Greeter:
def __init__(self, greeting):
self.greeting = greeting
self.count = 0 # Internal state
def __call__(self, name):
self.count += 1
return f"{self.greeting}, {name}! (Called {self.count} times)"
hello_greeter = Greeter("Hello")
print(hello_greeter("Alice"))
print(hello_greeter("Bob"))
Hello, Alice! (Called 1 times)
Hello, Bob! (Called 2 times)
2. Implementing Decorators with Classes
Decorators are a classic use case. A class-based decorator uses __init__ and __call__.
class CallCounter:
"""A decorator class that counts function calls."""
def __init__(self, func):
self.func = func
self.call_count = 0
def __call__(self, *args, **kwargs):
self.call_count += 1
print(f"{self.func.__name__} has been called {self.call_count} times")
return self.func(*args, **kwargs)
@CallCounter
def say_hello(name):
print(f"Hello, {name}")
say_hello("World")
say_hello("Python")
say_hello has been called 1 times
Hello, World
say_hello has been called 2 times
Hello, Python
3. For APIs and Configuration
Libraries often use callable objects to provide a clean interface. The object is configured first, then called.
This pattern is common in web frameworks and machine learning libraries. You can also explore how object composition works in our guide on Python Objects in Objects: Nested Data Guide.
Key Takeaways and Conclusion
A callable object is anything you can use with (). The callable() built-in function tests for this property.
Functions, methods, and classes are naturally callable. You can make your class instances callable by defining the __call__ method.
This turns an object into a functor. It retains internal state between calls.
Use callable instances to create smart, configurable functions. They are perfect for decorators, middleware, and factory patterns.
Mastering callables makes your code more expressive and Pythonic. It unlocks advanced patterns used in professional codebases.
Remember, understanding objects is fundamental in Python. To see how objects interact in data serialization, check out our JSON Serialization Guide for Custom Python Objects.