Python String isdecimal() Method
The isdecimal() method checks if the string contains only decimal characters.
Python String isdecimal() Syntax
isdecimal() method syntax:
str.isdecimal()
Python String isdecimal() Parameters
- None.
Python String isdecimal() Return Value
- True – if all characters in the string are decimal characters.
- False – if at least one character is not a decimal character.
Python String isdecimal() Example#1
The following example demonstrates the use of the isdecimal() function.
s = "12345"
print(s.isdecimal())
# contains alphabets
s = "12apidemos34"
print(s.isdecimal())
# contains numbers and spaces
s = "12 34"
print(s.isdecimal())
Output:
Python String isdecimal() Example#2
The difference between isdigit() and isdecimal():
expr = "4²"
print("expr isdigit()?", expr.isdigit())
print("expr isdecimal()?", expr.isdecimal())
Output:
Python String isdecimal() Example#3
Difference between isnumeric() and isdecimal():
expr = "⅔"
print("expr isnumeric()?", expr.isnumeric())
print("expr isdecimal()?", expr.isdecimal())
Output: