This article mainly introduces the strisnotcallable problem details in Python and relevant information on solutions. if you need it, refer to the str is not callable problem details in Python and solutions.
Question:
During the Python code running, an error message is displayed:
Python code:
def check_province_code(province, country): num = len(province) while num <3: province = ''.join([str(0),province]) num = num +1 return country + province
Running error message:
check_province_code('ab', '001')---------------------------------------------------------------------------TypeError Traceback (most recent call last)
in
()----> 1 check_province_code('ab', '001')
in check_province_code(province, country) 3 4 while num <3:----> 5 province = ''.join([str(0),province]) 6 num = num +1 7 TypeError: 'str' object is not callable
Problem analysis and Troubleshooting:
From the error information analysis, str is not a Callable object, but it can be called before. in the python api documentation, it is a built-in function of python, why can't I use it?
Continue to verify.
Run str (123) on the command line to convert the number to string:
>>> str(1233)---------------------------------------------------------------------------TypeError Traceback (most recent call last)
in
()----> 1 str(1233) TypeError: 'str' object is not callable
Now the problem is clearly defined. str is absent. I thought about it carefully. I used str randomly when I defined the variable, so it was overwritten by the str function. The following operations are performed:
str = '123'
Restore the default str function
Restart the python application and remove the code covered by str.
Summary
Python has many built-in functions and classes. when you define variables, remember not to overwrite or repeat them with their names.
Thank you for reading this article. I hope it will help you. thank you for your support for this site!
For more details about the str is not callable problem in Python and the solution, refer to PHP!