Last modified: Apr 23, 2026 By Alexander Williams
Fix 'str' Object Not Callable Error
Python is a powerful language, but it can throw confusing errors. One common error beginners face is TypeError: 'str' object is not callable. This error stops your code and can be frustrating. However, it is easy to fix once you understand the cause.
This article explains why this error happens. You will see simple examples and learn how to solve it. By the end, you will know how to avoid this error in your own code.
What Does This Error Mean?
The error TypeError: 'str' object is not callable means you tried to call a string like a function. In Python, you use parentheses () to call a function. If you accidentally put parentheses after a string variable, Python thinks you want to call it. Since strings are not functions, Python raises this error.
Think of it like this: you cannot use a string as a command. You can only use it as data.
Common Causes of This Error
There are three main reasons for this error. Each involves accidentally using a string where a function should be.
1. Using a Variable Named str
Python has a built-in function called str(). This function converts other data types to strings. If you create a variable with the name str, you overwrite the built-in function. Later, when you try to use str(), Python finds your variable instead of the function. This causes the error.
Here is an example:
# Bad: overwriting the str() function
str = "Hello"
number = 123
text = str(number) # Error: 'str' object is not callable
When you run this code, you get:
Traceback (most recent call last):
File "main.py", line 4, in
text = str(number)
TypeError: 'str' object is not callable
To fix this, rename your variable to something else. For example, use my_string instead of str.
# Fixed: use a different variable name
my_string = "Hello"
number = 123
text = str(number) # Works fine now
print(text) # Output: '123'
2. Missing Operator in a String Concatenation
Sometimes you may forget to add a + operator when joining strings. If you put parentheses after a string, Python thinks you are calling it.
Example:
# Bad: missing + operator
name = "Alice"
greeting = "Hello" (name) # Error: 'str' object is not callable
This code tries to call the string "Hello" as a function. The correct way is:
# Fixed: use + operator
name = "Alice"
greeting = "Hello " + name
print(greeting) # Output: 'Hello Alice'
You can also use an f-string to avoid this error.
# Alternative: use f-string
name = "Alice"
greeting = f"Hello {name}"
print(greeting) # Output: 'Hello Alice'
3. Using a String Variable as a Function
This happens when you store a string in a variable and then try to call it with (). For example, you might think you are calling a function, but the variable is actually a string.
Example:
# Bad: using a string as a function
function_name = "print"
function_name("Hello") # Error: 'str' object is not callable
Here, function_name is a string, not the actual print() function. To fix this, use the actual function reference.
# Fixed: use the actual function
function_name = print
function_name("Hello") # Output: 'Hello'
If you need to call a function by its name as a string, use a dictionary or getattr() for more advanced cases.
How to Debug This Error
When you see this error, check these steps:
- Look at the line number in the error message.
- Find the variable or expression before the parentheses
(). - Verify that it is a function, not a string.
- Search your code for any variable named
str,int,list, or other built-in names.
If you find a variable with a built-in name, rename it. This is a common mistake for beginners.
Preventing the Error
Good coding habits help you avoid this error. Here are some tips:
- Never name variables after built-in functions. Avoid names like
str,int,list,dict,print, andinput. - Use descriptive variable names. Instead of
str, usetextormessage. - Check your parentheses. Make sure you are not accidentally adding
()after a string. - Use an IDE or linter. Tools like PyCharm or pylint can warn you about overwriting built-in functions.
For more help with Python errors, read our guide on Python TypeError: Causes and Fixes. It covers other common type errors and solutions.
Real-World Example
Let's look at a practical scenario. Imagine you are building a program that asks for a user's name and age. You accidentally use str as a variable.
# Problematic code
str = input("Enter your name: ")
age = 25
message = "Your name is " + str(age) # Error!
This code will fail because str is now a string, not the str() function. The fix is simple: rename the variable.
# Fixed code
name = input("Enter your name: ")
age = 25
message = "Your name is " + str(age) # Works fine
print(message) # Output: 'Your name is 25'
Always choose meaningful variable names. This makes your code easier to read and prevents errors.
Conclusion
The TypeError: 'str' object is not callable error is common but easy to fix. It happens when you try to call a string as a function. The main causes are overwriting the built-in str() function, missing operators in string concatenation, or using a string variable as a function.
To solve it, check the line where the error occurs. Ensure you are not using parentheses after a string. Rename any variables that shadow built-in functions. With practice, you will spot and fix this error quickly.
Remember to write clean code with descriptive variable names. This helps you avoid many common Python errors. For more debugging tips, explore our Python TypeError: Causes and Fixes article.