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

Juho Schultz juho.schultz at helsinki.fi
Wed Dec 21 06:51:07 EST 2005


Neuruss wrote:
> Can't we just check if the string has digits?
> For example:
> 
> 
>>>>x = '15'
>>>>if x.isdigit():
> 
> 	print int(x)*3
> 
> 	
> 45
> 
> 
No, we can't. '-15' has non-digits but is a valid int.

Another point is that the try-except
can also be used for string-to-float conversion....




More information about the Python-list mailing list