A detailed explanation and solution of STR is not callable in Python

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.