93 of 151 menu

The isdigit method

The isdigit method checks that a string consists only of digits. Nothing is passed to the method parameters. The method returns the Boolean values ​​True or False.

Syntax

string.isdigit()

Example

Let's assume that the line consists only of numbers:

txt = '12345' print(txt.isdigit())

Result of code execution:

True

Example

Now let's say there are other symbols in the line:

txt = '12345ab' print(txt.isdigit())

Result of code execution:

False

See also

  • method isnumeric,
    which checks if a string contains only numbers
  • method isspace,
    which checks if a string contains only spaces
  • method isalnum,
    which checks if a string contains letters and numbers
  • method isalpha,
    which checks if a string contains only letters
byenru