Python string isdecimal() method example

In this source code example, we will demonstrate how to use the isdecimal() method to check if all characters in a string are decimal characters.

Use the Python string isdecimal() method to check if all characters in a string are decimal characters.

Python string isdecimal() method example

The following example uses the isdecimal() method to check if all characters in a string are decimal characters:

quantity = "150"
print(quantity.isdecimal())

Output:

True
The following example returns False because the string contains the character '.' which is not a decimal character:
price = '100.5'
print(price.isdecimal())

Output:

False

Comments