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

Grant Edwards grante at visi.com
Fri Dec 23 09:27:01 EST 2005


On 2005-12-23, Fredrik Lundh <fredrik at pythonware.com> wrote:
> 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.

I know.  

My point was that '15'.isdigit() returning True is in my
opinion "surprising" since '15' is not a digit in the most
obvious meaning of the phrase.  In language design, "surprise"
is a bad quality.

It's like saying that [1,2,3,4] is an integer.

-- 
Grant Edwards                   grante             Yow!  Join the PLUMBER'S
                                  at               UNION!!
                               visi.com            



More information about the Python-list mailing list