Python 3 reference · String Methods

Python String isdigit() Method

Return True if every character is a digit, including superscripts like ². Signs, spaces and decimal points return False.

Python 3 Since 3.0

Syntax

str.isdigit()

Return value

True or False.

Examples

What counts as a digitTry it yourself
print("2026".isdigit(), "3.14".isdigit(), "-1".isdigit(), "²".isdigit())

Output

True False False True
Validate a PINTry it yourself
pin = "0042"
print(len(pin) == 4 and pin.isdigit())

Output

True

Version history

VersionChange
Python 3.0Added