Python - String isdigit() Method


Advertisements

The string isdigit() method is used to check whether all characters of the string are digits or not. It returns true when all characters of the string are digits, else returns false. Digit characters belongs to numbers 0 - 9 and exponential format (example- 5²).

Syntax


string.isdigit()

Example:

In the below example, isdigit() method to used to check whether all characters of the string are digits or not.

MyString = "12345"
print(MyString.isdigit())

MyString = "5²"
print(MyString.isdigit())

Output

True

True

Example:

In the below example, isdigit() method to used to check whether all characters of the unicode string object are digits or not.

MyString = "\u0035"        #unicode for 5
print(MyString.isdigit())

MyString = "\u0035\u00B2"  #unicode for 5²
print(MyString.isdigit())

Output

True

True





String Methods
Advertisements