English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
If all characters in the string are decimal characters, the isdecimal() method will return True. If not, it will return False.
The syntax of isdecimal() is
string.isdecimal()
isdecimal() does not accept any parameters.
isdecimal() returns:
True If all characters in the string are decimal characters.
False If at least one character is not a decimal character.
s = "28212" print(s.isdecimal()) # Contains letters s = "32ladk3" print(s.isdecimal()) # Contains letters and spaces s = "Mo3 nicaG el l22er" print(s.isdecimal())
When running the program, the output is:
True False False
Superscripts and subscripts are considered number characters, not decimals. If the string contains these characters (usually written using unicode), isdecimal() returns False.
Similarly, Roman numerals, currency denominations and fractions are considered numbers (usually written using unicode), not decimals. In this example, isdecimal() also returns False.
There are two methods, dinst digit() is used to check if the string is composed only of numbers and isnumeric() method detects if the string is composed only of numbers, this method is only for unicode objects.
Learn aboutisdigit()andisnumeric()More information about the method.
s = ''23455' print(s.isdecimal()) #s = '²'3455' s = '\u00B'23455' print(s.isdecimal()) # s = '½' s = '\u00BD' print(s.isdecimal())
When running the program, the output is:
True False False