Editor

TypeError: 'str' object is not callable

What it means

You put round brackets after something that is a string, so Python tried to call it like a function. Usually a variable has taken the name of a function, such as str or one of your own, or () was used where [] was meant.

1. A variable named `str`

This raises the error

Broken
str = "Score: "
points = 42
print(str + str(points))
Output
Traceback (most recent call last):
  File "<exec>", line 3, in <module>
TypeError: 'str' object is not callable

The fix

Fixed
label = "Score: "
points = 42
print(label + str(points))
Output
Score: 42

Naming a variable str hides the built-in str() function for the rest of the program. The same happens with input, len, max, sum and list. Pick a different name.

Try fixing it yourself in the editor

2. Reusing a function's name for its result

This raises the error

Broken
def title():
return "Monthly report"
title = title()
print(title())
Output
Traceback (most recent call last):
  File "<exec>", line 5, in <module>
TypeError: 'str' object is not callable

The fix

Fixed
def title():
return "Monthly report"
heading = title()
print(heading)
Output
Monthly report

After title = title(), the name title holds the string, not the function. A separate name for the result keeps the function callable.

Try fixing it yourself in the editor

3. Round brackets instead of square brackets

This raises the error

Broken
word = "python"
print(word(0))
Output
Traceback (most recent call last):
  File "<exec>", line 2, in <module>
TypeError: 'str' object is not callable

The fix

Fixed
word = "python"
print(word[0])
Output
p

Square brackets pick a character out of a string. Round brackets mean "call this", and a string cannot be called.

Try fixing it yourself in the editor

When you see this error, check

  • Search your code for str =, input =, len = and similar names, and rename them.
  • In this editor, variables stay in memory between runs. After renaming, choose Restart Python in the More menu so the old str is gone.
  • Use [] to pick a character from a string, () only to call a function.
  • Check for a missing operator between a string and brackets, such as "Total" (5).

All Python errors · How to read a traceback · Step through your code