> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Callable

A callable in Python is any object that can be invoked using the function call operator `()`. At the architectural level, an object is recognized as callable if its underlying class implements the `__call__` special method.

When the Python interpreter encounters the syntax `object()`, it resolves the special method on the object's class rather than the instance itself. This translates the invocation into `type(object).__call__(object)`. Consequently, assigning a `__call__` attribute directly to an instance will not make it callable via `()`; the method must be defined within the class dictionary.

## The `callable()` Built-in Function

Python provides the built-in `callable()` function to determine if an object supports invocation. It accepts a single object as an argument and returns a boolean.

```python theme={"dark"}

# Syntax
callable(object)


# Examples
callable(len)          # True (Built-in function)
callable(lambda x: x)  # True (Anonymous function)
callable([1, 2, 3])    # False (List object)
callable(int)          # True (Class)
```

*Technical Nuance:* If `callable()` returns `True`, the call may still fail (e.g., due to incorrect arguments or an internal exception). However, if it returns `False`, invoking the object will strictly raise a `TypeError`.

## The `__call__` Protocol

You can make any custom class instance callable by defining the `__call__` method within its class definition. This integrates the object into Python's callable data model.

```python theme={"dark"}
class StateTracker:
    def __init__(self):
        self.invocations = 0

    def __call__(self, *args, **kwargs):
        self.invocations += 1
        return self.invocations


# Instantiation
tracker = StateTracker()


# Verification
is_callable = callable(tracker)  # True


# Invocation
result_1 = tracker()  # Returns 1
result_2 = tracker()  # Returns 2
```

## Standard Callable Types

According to the Python data model, the following object types are inherently callable:

1. **User-Defined Functions:** Objects created using the `def` statement or `lambda` expressions.
2. **Built-in Functions and Methods:** Functions implemented in C (in CPython), such as `print()` or `list.append()`.
3. **Classes:** Invoking a class object triggers the instantiation process. It calls `__new__()` to create the object. The `__init__()` method is subsequently executed to initialize the object's state *only* if `__new__()` returns an instance of the class being instantiated. If `__new__()` returns an object of a different type, `__init__()` is skipped entirely.
4. **Class Instances:** Any instance of a class where the `__call__` method is defined on the class itself.
5. **Methods:** Functions bound to a class instance. When invoked, the instance is implicitly passed as the first argument (`self`).
6. **Generator Functions:** Functions containing the `yield` keyword. Invoking them returns a generator iterator object.
7. **Coroutines:** Functions defined with `async def`. Invoking them returns a coroutine object rather than executing the function body immediately.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Python Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
