THE WORLD'S LARGEST WEB DEVELOPER SITE

Python String isdigit() Method

❮ String Methods


Example

Check if all the characters in the text are digits:

txt = "50800"

x = txt.isdigit()

print(x)
Run example »

Definition and Usage

The isdigit() method returns True if all the characters are digits, otherwise False.

Exponents, like ², are also considered to be a digit.


Syntax

string.isdigit()

Parameter Values

No parameters.


More Examples

Example

Check if all the characters in the text is alphabetic:

a = "\u0030" #unicode for 0
b = "\u00B2" #unicode for ²

print(a.isdigit())
print(b.isdigit())
Run example »

❮ String Methods