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

pythonstring.isdigit()

Example

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

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

Result of code execution:

pythonTrue

Example

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

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

Result of code execution:

pythonFalse

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