TypeError: 'str' object is not callable
Something you are calling like a function is a string. Almost always a variable called str, input or format has replaced the built-in function with the same name.
What it means
In Python, name(...) means call whatever name refers to right now. Built-in names such as str, input, sum and max are ordinary variables, not reserved words: assign a string to one and every later call to it in that scope tries to call the string.
Common causes
1. A variable or parameter named str
Inside the function, str is now the text you passed in, so str(n) calls a string.
Breaks
def label(str, n):
return str + " #" + str(n)Works
def label(text, n):
return text + " #" + str(n)2. Storing input() in a variable called input
The second call to input() calls the answer to the first one.
Breaks
input = input("Name: ")
age = input("Age: ")Works
name = input("Name: ")
age = input("Age: ")3. A string followed by brackets
A missing + or comma turns the brackets into a call.
Breaks
message = "Total: "(total)Works
message = "Total: " + str(total)How to find it in your own code
Look at the name directly before the ( on the failing line and print(type(name)). If it says <class 'str'>, search upwards for an assignment to that name and rename the variable. Never reuse str, list, dict, input, sum, max, min, type or id as a variable name.
Still not sure why yours breaks?
Paste it into the visualizer and watch it run line by line, with every variable at every step. Free, and it runs in your browser.