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.
The following example returns False because the string contains the character '.' which is not a decimal character:
Python
Python String
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
price = '100.5'
print(price.isdecimal())
Output:
False
Comments
Post a Comment