Strisnotcallable in Python and its solution

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

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.