isdigit() String Method in Python with Examples
isdigit()
method returns True
if the string is a digit string otherwise it returns False
.
A string is a decimal string if all characters in the string are digit and there is at least one character in the string.
Example 1: isdigit() String Method
message = '12345'
if message.isdigit():
print('"%s" is digit string.' %(message))
else:
print('"%s" is not digit string.' %(message))
Output
"12345" is digit string.
Example 2: isdigit() String Method
message = '12345 cat'
if message.isdigit():
print('"%s" is digit string.' %(message))
else:
print('"%s" is not digit string.' %(message))
Output
"12345 cat" is not digit string.
Related String Methods