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