Best way to check if string is an integer?

Mark Dickinson dickinsm at gmail.com
Sat Apr 5 19:25:49 EDT 2008


On Apr 5, 6:19 pm, skanem... at yahoo.se wrote:
> which is the best way to check if a string is an number or a char?
> could the 2nd example be very expensive timewise if i have to check a
> lot of strings?

You might be interested in str.isdigit:

>>> print str.isdigit.__doc__
S.isdigit() -> bool

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

Mark



More information about the Python-list mailing list