Python string isdecimal() method
Python String isdecimal() Method
Description
The isdecimal() method checks whether all characters in a string are decimal characters. All digits 0-9 and their Unicode representations are considered decimal characters.
Syntax
var.isdecimal()
Parameters
None
Return Value
This method returns true if all characters in the string are decimal characters. Otherwise, it returns false.
Example
The following example demonstrates the use of the isdecimal() method.
var = "123"
var1 = var.isdecimal()
print ("Original string:", var)
print ("Only decimal characters?:", var1)
var = "u0031u0032u0033"
var2 = var.isdecimal()
print ("Original string:", var)
print ("Only decimal characters?:", var2)
var = "123.34"
var3 = var.isdecimal()
print ("Original string:", var)
print ("Only decimal characters?:", var3)
When you run this program, it will produce the following output −
Original string: 123
Only decimal characters? : True
Original string: 123
Decimal characters only? : True
Original string: 123.34
Decimal characters only? : False
Here, 0031 is the Unicode encoding for the character “1”, 0032 is the Unicode encoding for the character “2”, and 0033 is the Unicode encoding for the character “3”.