isdecimal()
« All String methods
isdecimal()
Returns True if all chars are decimal ( 0 to 9) in a string, Otherwise False is returned.
my_str='12345'
print(my_str.isdecimal()) # Output is True
my_str='234ab'
print(my_str.isdecimal()) # Output is False
my_str='234.45'
print(my_str.isdecimal()) # Output is False
Use google to search translate 1234 to chinese , then use the output like this.
my_str='一千二百三十四'
print(my_str.isnumeric()) # True
print(my_str.isdigit()) # False
print(my_str.isdecimal()) # False
One more example
my_str = '2²'
print(my_str.isnumeric()) # True
print(my_str.isdigit()) # True
print(my_str.isdecimal()) # False
my_str = '½'
print(my_str.isnumeric()) # True
print(my_str.isdigit()) # False
print(my_str.isdecimal()) # False
isdigit() will allow only digits 0-9
« All String methods
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com