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

Kent Johnson kent at
Wed Dec 21 13:36:15 CET 2005

Steven D'Aprano wrote:
> On Wed, 21 Dec 2005 03:37:27 -0800, Neuruss wrote:
>>>>>x = '15'
>>>>>if x.isdigit():
>>	print int(x)*3
> 15 is not a digit. 1 is a digit. 5 is a digit. Putting them together to
> make 15 is not a digit.

Maybe so, but '15'.isdigit() == True:

     S.isdigit() -> bool

     Return True if all characters in S are digits
     and there is at least one character in S, False otherwise.

  >>> '15'.isdigit()

though your other points are valid and I agree this is not the right solution to the OP.


More information about the Python-list mailing list