str.isdigit()
Added in v3.x · Updated March 13, 2026 · String Methods
stdlib strings character-validation
The isdigit() method returns True if all characters in the string are digits, and False otherwise.
Signature
str.isdigit()
Parameters
None. This method takes no parameters.
Return Value
Returns a boolean value:
True— all characters are digits (0-9)False— at least one character is not a digit
Examples
>>> "12345".isdigit()
True
>>> "123.45".isdigit()
False
>>> "".isdigit()
False
>>> "-123".isdigit()
False
>>> "\u00b2".isdigit() # superscript 2
True
Common Use Cases
Input validation:
def get_integer_input(prompt):
user_input = input(prompt)
if user_input.isdigit():
return int(user_input)
return None
Filtering digit strings:
words = ["apple", "123", "3.14", "42"]
digits_only = [w for w in words if w.isdigit()]
# ["123", "42"]
Notes
- Leading signs (
+,-) are not considered digits. - Decimal points and commas are not digits.
- Unicode superscripts (like
\u00b2) are considered digits. - For checking integers including negative numbers, use a custom function or regex.