TypeError: 'str' object is not callable — how to fix
Traceback (most recent call last):
File "main.py", line 4, in <module>
print(str(42))
TypeError: 'str' object is not callable
Quick fix: Find where the name was reassigned (e.g. str = "...", input = input()), rename that variable, and restart the interpreter/kernel (del str in a notebook). Use s[0] not s(0) for indexing, and "..." % x or f-strings, not "..."(x).
What it means
x() calls x. When x is a string, Python raises TypeError: 'str' object is not callable. Look at the line in the traceback and ask, for every name( on it: is name actually a string right now?
print(type(str), type(input)) # should be <class 'type'> / builtin_function_or_method
Cause 1: a variable shadows the str built-in
str = "hello"
...
label = str(42) # TypeError: 'str' object is not callable
Rename the variable (text, s, name...). In Jupyter or an interactive shell, the bad assignment persists even after you edit the cell — undo it:
del str # restores the built-in
or restart the kernel.
The same happens with other built-ins: input, format, type, id, print (print = "x"), max, sum. A classic:
input = input("Name: ")
age = input("Age: ") # TypeError: 'str' object is not callable
Cause 2: an attribute or method name collides
class User:
def __init__(self, name):
self.name = name
def name(self): # replaced by the instance attribute
return self.name
User("a").name() # TypeError: 'str' object is not callable
The instance attribute self.name (a string) hides the method. Rename one of them (get_name), or use @property and access it without parentheses:
class User:
def __init__(self, name):
self._name = name
@property
def name(self):
return self._name
User("a").name # no ()
Also: calling a property with () gives the same error, e.g. response.text() in requests — .text is a string property; use response.text (but response.json() is a method).
Cause 3: parentheses instead of brackets
s = "abcdef"
s(0) # wrong
s[0] # 'a'
Cause 4: missing operator when formatting
msg = "Total: %d" (total) # missing %
msg = "Hi " "there" (name) # missing +
Fix:
msg = "Total: %d" % total
msg = f"Total: {total}"
msg = "Hi " + name
Cause 5: a function was replaced by its result
def get_title(): return "Report"
get_title = get_title() # now a string
get_title() # TypeError
Or a callback parameter receives a string instead of a function:
def run(callback):
callback()
run("my_func") # wrong: pass my_func, not its name
run(my_func)
If you need to look up a function by name, use a dict: handlers = {"save": save} then handlers[name]().
Finding the culprit fast
Search for assignments to the name:
grep -nE '^\s*(str|input|format|type)\s*=' *.py
Linters catch this too: pylint reports redefined-builtin (W0622), and ruff has rule A001 (builtin-variable-shadowing).
Last updated 2026-11-02.