python isdecimal
Python hosting: Host, run, and code Python in the cloud!
Python’s isdecimal()
String Method: A Quick Guide
The isdecimal()
method in Python’s string class helps in determining whether a string contains only decimal characters. It is a handy method when working with numeric validations.
Syntax
The isdecimal()
method follows a straightforward format:
str.isdecimal() |
Parameters
This method does not take any parameters.
How does isdecimal()
work?
The method returns True
if all characters in the string are decimals (0-9) and the string is not empty, otherwise, it returns False
.
Examples
To better understand the method, consider the following examples:
sample_str = u"1.234" |
The output for the above examples will be:
False True
This is because the first string contains a period (.), which is not a decimal character. In contrast, the second string consists only of decimal characters.
Posted in documentation
Leave a Reply: