A detailed explanation and solution of STR is not callable in Python
Questions raised:
In Python code, during the run, an error message is encountered:
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
Error message to run:
Check_province_code (' ab ', ' 001 ')--------------------------------------------------------------------------- TypeError Traceback (most recent) <ipython-input-44-02ec8a351cce> in <module> ()----> 1 Check_province_code (' ab ', ' 001 ') <ipython-input-43-12db968aa80a> 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 message analysis, STR is not a callable object, but it can actually be called, and in the Python API document, it is a python built-in function ah, how can not be used?
Just go ahead and verify it.
Execute STR (123) at the command line and convert the number to string:
>>> Str (1233)---------------------------------------------------------------------------TypeError Traceback (most recent) <ipython-input-45-afcef5460e92> in <module> ()----> 1 str (1233) TypeError: ' str ' object is not callable
This problem is clearly defined, originally did not have STR, carefully think about the original in the definition of variables, the random use of STR, so it is covered by the STR function. An operation similar to the following is done:
str = ' 123 '
Restore the default str function
Restart the Python app to remove the section of code that is covered by Str.
Summarize
There are many functions and classes built into Python, so remember not to overwrite them or repeat them with their names when defining variables.
Thank you for reading, hope to help everyone, thank you for the support of this site!