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
print("2026".isdigit(), "3.14".isdigit(), "-1".isdigit(), "²".isdigit())
Output
True False False True
pin = "0042"
print(len(pin) == 4 and pin.isdigit())
Output
True
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
str.isdecimal()· Return True if every character is a decimal digit (0–9 and their equivalents in other scripts). The strictest digit check.str.isnumeric()· Return True if every character is numeric, including digits, fractions like ½ and numerals from other scripts.str.isalnum()· Return True if every character is a letter or a digit and the string isn't empty.- Python Strings · tutorial