TypeError: '...' object is not callable
TypeError: '...' object is not callable
DodaTech
2 min read
TypeError: '...' object is not callable appears when you use parentheses () on something that isn’t a function, class, or any callable object.
What It Means
You tried to “call” something with () that Python can’t invoke. Only functions, classes, and objects with a __call__ method are callable. Integers, strings, lists, and most other types are not.
Why It Happens
- Using parentheses on a non-function variable (e.g.
x = 5; x()) - Assigning a value to a name that was previously a function (e.g.
len = 10; len("hello")) - Missing an operator between parentheses (e.g.
print("a")("b")instead ofprint("a", "b")) - Calling a string or number by mistake
- Method vs property confusion — using
()on a property that returns a non-callable
How to Fix It
Step 1: Don’t call non-callable objects
# BAD — integers aren't callable
x = 42
print(x())
# GOOD
x = 42
print(x)Step 2: Don’t overwrite function names
# BAD — 'max' is now an integer, not a function
max = 100
print(max(10, 20)) # TypeError: 'int' object is not callable
# GOOD
max_value = 100
print(max(10, 20)) # Works: max is still the built-inStep 3: Fix accidental double-parentheses
# BAD — this calls the result of print(), which is None
print("hello")("world")
# GOOD
print("hello", "world")
# Or on separate lines:
print("hello")
print("world")Step 4: Use methods correctly
# BAD — 'upper' is a method, but 'name' is a string
name = "alice"
print(name.upper) # <built-in method upper...> — missing ()
# GOOD
print(name.upper()) # "ALICE"Step 5: Check class vs instance confusion
class MyClass:
def __init__(self):
self.value = 10
# BAD
obj = MyClass # Missing parentheses — obj is the class itself
print(obj()) # This might work (creates instance), but not what you wanted
# GOOD
obj = MyClass() # obj is now an instance
print(obj.value)Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro