Home »
Python
Python String isdecimal() Method
By IncludeHelp Last updated : December 08, 2024
Python String isdecimal() Method
The isdecimal() is an in-built method in Python, which is used to check whether a string contains only decimal characters or not.
Note:
- Decimal characters contain all digits from 0 to 9.
- String should be Unicode object - to define a string as Unicode object, we use u as prefix of the string value.
Syntax
String.isdecimal();
Return Type
- true - If all characters of the string are decimal characters then method returns true.
- false - If any of the characters of the string is not a decimal character then method returns false.
Example
# str1 with only decimal characters
str1 = u"362436"
print(str1.isdecimal ())
# str2 with alphabets and decimal characters
str2 = u"Hello36"
print(str2.isdecimal ())
# str3 with alphabets and special characters
str3 = u"@Hell36#"
print(str3.isdecimal ())
Output
True
False
False
Reference: String isdecimal()