Solution to TypeError: 'str' object is not callable in Python

Solution to TypeError: 'str' object is not callable in Python

'str' object is not callable generally occurs when an attempt is made to call an object that cannot be called.

After a closer look at the code, it turned out that a variable was named str before, and then it was called as the underlying str(). In fact, at this time, it is no longer a low-level function of Python.

variable named str

The variable is called as a function

In fact, pycharm has already underlined the problematic code.

Solution: Rename the variable.

In the future, remember that the defined variable names should not conflict with the underlying functions of Python.

Guess you like

Origin blog.csdn.net/fei347795790/article/details/129596740