How to check if a string "is" an int?

Fredrik Lundh fredrik at
Fri Dec 23 11:22:55 CET 2005

Grant Edwards wrote:

> > So? the isdigit method tests whether all characters are digits.
> >
> >>>> '15'.isdigit()
> > True
> But that is "obviously" wrong, since '15' is not a digit.

no, but all characters in the string belongs to the "digit" character
class, which is what the "is" predicates look for.


>>> "\t".isspace()
>>> "Life of Brian".istitle()
>>> u"\N{GREEK CAPITAL LETTER BETA}".isalpha()

and so on.


More information about the Python-list mailing list