Python String isdigit() Method

Example

Check if all characters in the text are numbers:

txt = "50800"
x = txt.isdigit()
print(x)

Run Instance

Definition and Usage

If all characters are numbers, the isdigit() method will return True, otherwise it will return False.

Exponents (e.g., ²) are also considered numbers.

Syntax

string.isdigit()

Parameter value

No parameters.

More Examples

Example

Check if all characters in the text are letters:

a = "\u0030" #unicode for 0
b = "\u00B2" #unicode for ²
print(a.isdigit())
print(b.isdigit())

Run Instance