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:
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
Free Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course