![]() |
VOOZH | about |
In Python, the isdecimal() method is a quick and easy way to check if a string contains only decimal digits. It works by returning True when the string consists of digits from 0 to 9 and False otherwise. This method is especially useful when we want to ensure that user inputs or string data are strictly numeric without any special characters or spaces.
True False
Table of Content
string.isdecimal()
The method returns:
A string that contains a decimal point or any other non-digit characters will return False. For example, strings like "123.45" or "100,000" will fail the check because the period (.) and the comma (,) are not considered decimal digits.
False False
The isdecimal() method does not consider spaces or symbols as decimal characters. Let’s see an example:
False
There are certain numeric characters from other writing systems or formats that look like digits but are not considered decimal digits in Python. For example, the Arabic-Indic numerals or other scripts that represent numbers differently.
True
False
The isdecimal() method also returns False when the string contains negative signs (-) or other symbols like currency symbols ($, €, etc.). The presence of any non-decimal character will cause the method to return False.
False False