Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Python string isdecimal() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 alphabets
s = "12geeks34"
print(s.isdecimal())
  
# contains numbers and spaces
s = "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

My Personal Notes arrow_drop_up
Last Updated : 25 Aug, 2022
Like Article
Save Article
Similar Reads
Related Tutorials