How to check if a string "is" an int?
Fredrik Lundh
fredrik at pythonware.com
Fri Dec 23 05:22:55 EST 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.
cf.
>>> "\t".isspace()
True
>>> "Life of Brian".istitle()
False
>>> u"\N{GREEK CAPITAL LETTER BETA}".isalpha()
True
and so on.
</F>
More information about the Python-list
mailing list