Python String isdecimal Method - Python Tutorial | Logic Practice
Python Course / Data Types / Python String isdecimal Method

Python String isdecimal Method

BLUF: This lesson on Python String isdecimal Method provides a comprehensive guide to understanding and implementing this concept in Python. Whether you're a beginner or looking to refresh your knowledge, you'll find clear explanations and interactive code examples here.
Key Concept: Python String isdecimal Method

Mastering Python String isdecimal Method is essential for building efficient Python applications. Focus on the syntax and the best practices highlighted in this tutorial.

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:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience