# Python String isdecimal()

The Python String isdecimal() method is a built-in function that returns true if all the characters in a string are decimal. If one of the characters is not decimal in the string, it returns false.

## Syntax

The Syntax of `isdecimal()` method is:

`string.isdecimal()`

## Parameters

The `isdecimal()` method does not take any parameters.

## Return Value

The `isdecimal()` method returns

• `True` if all the characters in a string are valid decimal characters.
• `False` if one or more characters in a string are not decimal characters.

## Example 1: Working of isdecimal() method in Python

``````
# Python3 program to demonstrate the use
# of isdecimal()

s = "12345"
print(s.isdecimal())

# contains alphabets
s = "123Hello123"
print(s.isdecimal())

# contains numbers and spaces
s = "12345 6789"
print(s.isdecimal())``````

Output

``````True
False
False``````

## Example 2: String Containing digits and Numeric Characters

The superscript and subscript are considered digit characters and not decimals. If the string contains subscript or superscript the `isdecimal()` method will return False.

Similarly, roman numbers, currencies, and fractions are considered numeric numbers and not decimals. The `isdecimal()` method will return `False` if it finds these characters.

It is recommended to use isdigit() method and `isnumeric()` method to check if the characters are valid digits and numeric characters respectively.

``````
# Python3 program to demonstrate the use
# of isdecimal()

# vaid decimal
s = '12345'
print(s.isdecimal())

# in case of digit
#s = '²123'
s = '\u00B2123'
print(s.isdecimal())

# incase of numeric
# s = '½'
s = '\u00BD'
print(s.isdecimal())``````

Output

``````True
False
False``````

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

## TypeError: method() takes 1 positional argument but 2 were given

If you define a method inside a class, you should add self as the first argument. If you forget the self argument, then Python will raise TypeError: method() takes 1 positional…

## How to Create a Pie Chart in Seaborn

We do not have any built-in function to create Pie chart in seaborn, but with the help of Matplotlib, we can create a pie chart and leverage seaborn for color…

## Python String rstrip()

Table of Contents Hide SyntaxParametersReturn Value Example 1: Working with rstrip() methodExample 2 – How to use rstrip() method in the real world? The Python String rstrip() method is a…

## How to Generate a random string of a given length in Python?

Table of Contents Hide Generate a random Mixed case alphabet stringGenerate a random Upper case alphabet stringGenerate a random Lower case alphabet stringGenerate a random Alphanumeric stringGenerate a random strong…

## Remove Character From String Python

Table of Contents Hide Python Remove a Character from a StringPython Remove Character from String using replace()Remove a single character from a stringRemove all occurrences of a character from a…

## [Solved] Python can’t Multiply Sequence by non-int of type ‘str’

Table of Contents Hide TypeError: can’t multiply sequence by non-int of type ‘str’Multiplying string with an integerMultiplying string with another stringSolution TypeError: can’t multiply sequence by non-int of type ‘str’Conclusion…