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

Python String isdigit Method

BLUF: This lesson on Python String isdigit 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 isdigit Method

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

The isdigit function in Python provides a True output when every character within the string constitutes a digit. Conversely, it yields a False result if there are no digit characters present in the string.

Python String isdigit Method Syntax

It has the following syntax:

Example

isdigit()

Parameters

No parameter is required.

Return

It returns either True or False.

Different Examples for Python String isdigit Method

Let’s explore a few examples of the isdigit method to gain a better understanding of its capabilities.

Example 1

An elementary illustration of digit verification utilizing the isdigit function.

Example

# Python isdigit() method example

# Variable declaration

str = '12345'

# Calling function

str2 = str.isdigit()

# Displaying result

print(str2)

Output:

Example 2

It yields a true value exclusively when every character is a digit. Refer to the example provided below.

Example

# Python isdigit() method example

# Variable declaration

str = "12345"

str3 = "120-2569-854"

# Calling function

str2 = str.isdigit()

str4 = str3.isdigit()

# Displaying result

print(str2)

print(str4)

Output:

Output

True

False

Example 3

In programming, we can utilize this to determine if a string includes any numeric characters.

Example

# Python isdigit() method example

# Variable declaration

str = "123!@#$"

if str.isdigit() == True:

    print("String is digit")

else:

    print("String is not digit")

Output:

Output

String is not digit

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