inspection

str.isdigit

Returns True if every character in the string is a digit and the string is non-empty. Includes Unicode digit characters like superscripts (²) but excludes signs, decimal points, and fractions like ½.

str.isdigit()

Parameters

Parameter Purpose
self operates on the calling string; takes no arguments
returns bool — False for empty strings

Examples

>>> '12345'.isdigit()
True

all ASCII digits

>>> '-1'.isdigit()
False

sign character disqualifies

>>> '3.14'.isdigit()
False

'.' is not a digit

>>> ''.isdigit()
False

empty string is always False

Gotcha

Empty string returns False. For accepting integer input use `s.lstrip('-').isdigit()` or, safer, wrap `int(s)` in try/except.

Related methods

← All Python string methods · Python built-ins