Python string isdecimal() Method
Python String isdecimal() function returns true if all characters in a string are decimal, else it returns False.
Python String isdecimal() Method Syntax:
Syntax: string_name.isdecimal(), string_name is the string whose characters are to be checked
Parameters:This method does not takes any parameters .
Return: boolean value. True – all characters are decimal, False – one or more than one character is not decimal.
Python String isdecimal() Method Example:
Python3
print("100".isdecimal()) |
Output:
True
Example: Basic Usage of Python String decimal() Method
Program to demonstrate the use of Python String decimal() Method.
Python3
s = "12345"print(s.isdecimal()) # contains alphabetss = "12geeks34"print(s.isdecimal()) # contains numbers and spacess = "12 34"print(s.isdecimal()) |
Output:
True False False
Difference between isdigit(), isnumeric() and isdecimal()
Example 1: Difference between isdigit() and isdecimal()
Here, Python String isdecimal() returns False because not all characters in the “expr” are decimal.
Python3
expr = "4²"print("expr isdigit()?", expr.isdigit()) print("expr isdecimal()?", expr.isdecimal()) |
Output:
expr isdigit()? True expr isdecimal()? False
Example 2: Difference between isnumeric() and isdecimal()
Python3
expr = "⅔"print("expr isnumeric()?", expr.isnumeric()) print("expr isdecimal()?", expr.isdecimal()) |
Output:
expr isnumeric()? True expr isdecimal()? False





Please Login to comment...