isdigit()
is an in-built method in python which is used for string manipulations. isdigit()
returns True
if all characters in the string are digits, else it returns False
. This Python String Method does not take any parameters.Syntax
string.isdigit()
Returns
True - If all the characters in the string are digits.False - If 1 or more non-digit characters are present in string.
Example 1
# checking for digit using isdigit
str = '987654321'
print(str.isdigit())
str = 'Houseno22'
print(str.isdigit())
Output
True
False
Example 2
# Checking for superscripts or subscripts with isdigit
str = '550\u2076'
print(str.isdigit())
Output
True
Note: fractions, roman numerals are not considered digits, hence
isdigit()
returns False
.
This method will work with unsigned integers, superscripts or subscripts.