TypeError: 'str' object is not callable
This means youβre trying to call a string as if it were a function β using () on something thatβs a string, not a function.
Fix 1: You named a variable str
The most common cause. You accidentally overwrote Pythonβs built-in str() function:
# β This shadows the built-in str()
str = "hello"
number = 42
text = str(number) # TypeError! str is now "hello", not the function
# β
Don't use 'str' as a variable name
message = "hello"
number = 42
text = str(number) # Works: "42"
Same problem with other built-ins: list, dict, int, float, type, input, print.
Quick fix β restart your Python session or delete the variable:
del str # Restores the built-in
Fix 2: Using parentheses instead of brackets
# β Parentheses = function call
name = "hello"
first_char = name(0) # TypeError!
# β
Brackets = indexing
first_char = name[0] # "h"
Fix 3: Missing an operator
# β Python thinks you're calling the string
greeting = "hello" "world"(x) # Confusing syntax
# β
Be explicit
greeting = "hello" + "world"
Fix 4: Calling a property thatβs a string
class User:
name = "Alice"
user = User()
# β name is a string, not a method
user.name() # TypeError!
# β
Access it as a property
print(user.name) # "Alice"
How to debug
Add a type check before the failing line:
print(type(str)) # Should be <class 'type'>, not <class 'str'>
If it prints <class 'str'>, youβve overwritten the built-in somewhere above.
Related resources
Related: Pip Install Error Fix Β· Module Not Found Error Fix Β· Python Syntaxerror General Fix