Attributeerror: ' int ' object has no attribute ' isdigit ' (isdigit function under Python)

Source: Internet
Author: User

The IsDigit function under Python:

the IsDigit () method detects whether a string consists of only numbers.

Grammar

IsDigit () method syntax: str. IsDigit()

The sample code is as follows:

Results:

  

The point I want to say is:

There's going to be a hole in there. Number = input ("1234:") gets a string of values from the console

Then there is

Python input () is equal to eval (raw_input (Prompt)), which is used to get input from the console.

Raw_input () treats all input as a string and returns the string type. Input (), when treated with a pure numeric input, has its own characteristics, which returns the type of the number entered (int, float).

When entering the full numeric string, this time the use of number.isdigit () will be an error (attributeerror: ' int ' object has no attribute ' isdigit '), is already a value of type int, in using this function, Must be an error.

Then it is best to choose the Raw_input () function, as the dynamic input method, the responsibility will fall into the pit.

Attributeerror: ' int ' object has no attribute ' isdigit ' (isdigit function under Python)

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.