How to Fix: Print Is No Longer a Function in Python
Have you ever encountered this strange error in Python?
TypeError: 'bytes' object is not callable
Or maybe this one?
TypeError: 'str' object is not callable
If you’re trying to use the print()
function and suddenly Python complains that it’s not callable, there’s a good chance you’ve accidentally overwritten the built-in print
function.
Let’s walk through what happened, how to fix it, and how to avoid it in the future.
What Went Wrong?
Here’s a simple example of how the problem starts:
print = "Hello"
print("World")
Python responds with:
TypeError: 'str' object is not callable
Why? Because you did this:
print = "Hello"
Now, the name print
is no longer referring to Python’s built-in function. It’s now a string variable, so when you try to use print("World")
, Python thinks you’re trying to “call” a string — which is not possible.
✅ How to Fix It
To fix the problem, you need to delete the variable assignment that shadowed the built-in function.
Step 1: Use del
to Remove the Reassignment
del print
This deletes your custom variable and restores access to the original built-in print()
function.
Step 2: Try Again
print("Now it works!")
Output:
Now it works!
What If You Assigned It to Another Type?
Sometimes, people assign it to other types like int
, list
, or bytes
, which causes the same issue:
print = b"binary"
print("oops")
# TypeError: 'bytes' object is not callable
Again, fix it with:
del print
Pro Tips to Avoid This Mistake
-
Never name your variables after built-in functions, like:
print
input
str
list
sum
max
, etc.
-
If you’re unsure, you can check the type of a name using:
print(type(print))
If it says <class 'str'>
or <class 'bytes'>
, you’ve overwritten it!
Summary
Problem | Cause | Fix |
---|---|---|
print() not working |
You assigned a value to print |
del print |
TypeError: 'str' object is not callable |
print = "hello" happened earlier |
del print |
Output doesn’t show | print is now a variable, not a function |
del print |
Final Word
Python is a very friendly language, but it’s easy to shoot yourself in the foot if you accidentally redefine built-in functions. Now that you know how to fix it, you’re one step closer to writing cleaner and safer Python code.