Best way to check if string is an integer?

skanemupp at skanemupp at
Sun Apr 6 00:19:59 CEST 2008

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?


value = raw_input()

    value = int(value)
except ValueError:
    print "value is not an integer"


c=raw_input("yo: ")
if c in '0123456789':
    print "integer"
    print "char"

or some other way?

More information about the Python-list mailing list