Python String isdigit() Method (original) (raw)

Last Updated : 01 May, 2025

The isdigit() method is a built-in Python function that checks if all characters in a string are digits. This method returns **True if each character in the string is a numeric digit (0-9) and **False otherwise. **Example:

Python `

a = "12345" print(a.isdigit())

b = "1234a5" print(b.isdigit())

`

*Explanation: In this example, a.isdigit() returns True because “12345*” consists entirely of numeric characters, while b.isdigit() returns False due to the non-numeric character “a**” in the string.

Syntax of isdigit()

s.isdigit()

**Parameters: This method does not take any parameters

**Returns:

Examples of isdigit()

Let’s explore some examples of isdigit() method for better understanding.

**Example 1: Here are example with a string containing only digits, a mixed-character string and an empty string.

Python `

Only digits

print("987654".isdigit())

Digits and alphabet

print("987b54".isdigit())

Empty string

print("".isdigit())

`

**Explanation:

**Example 2: The **isdigit() method can also be used to check numeric characters encoded in Unicode, such as the standard digit ‘1’ and other Unicode representations of numbers.

Python `

Unicode for '1'

a = "\u0031"
print(a.isdigit())

Devanagari digit for '1'

b = "\u0967"
print(b.isdigit())

`

**Explanation:

**Example 3: Here are example with Roman numerals, which are not recognized as digits.

Python `

print("I".isdigit())
print("X".isdigit())
print("VII".isdigit())

`

**Explanation: “I”.isdigit(), “X”.isdigit() and “VII”.isdigit() all return False as Roman numerals are not recognized as digits by isdigit().

**Related Articles: