Python String isdecimal Method

The isdecimal method in Python evaluates whether every character within a string is a decimal digit. Decimal digits are defined as those belonging to base 10.

This method returns boolean either true or false.

Syntax of Python String isdecimal Method

It has the following syntax:

Example

isdecimal()

Parameters

No parameter is required.

Return

It returns either True or False.

Different Examples for isdecimal Method in Python

Let us examine a few examples of the isdecimal method in order to gain insight into its capabilities.

Example 1

An illustrative example of the isdecimal function can be utilized to ascertain if a given string consists solely of decimal digits.

Example

# Python isdecimal() method example

# Variable declaration

str = "Example"

# Calling function

str2 = str.isdecimal()

# Displaying result

print(str2)

Output:

Example 2

Let's examine a floating-point value and observe the result. It will yield False if the string does not represent a decimal number.

Example

# Python isdecimal() method example

# Variable declaration

str = "123"     # True

str3 = "2.50"   # False

# Calling function

str2 = str.isdecimal()

str4 = str3.isdecimal()

# Displaying result

print(str2)

print(str4)

Output:

Output

True

False

Example 3

Here, we are checking special chars also.

Example

# Python isdecimal() method example

# Variable declaration

str = "123"     # True

str3 = "@#$"   # False

# Calling function

str2 = str.isdecimal()

str4 = str3.isdecimal()

# Displaying result

print(str2)

print(str4)

Output:

Output

True

False

Input Required

This code uses input(). Please provide values below: