Re: Best way to check if string is an integer?



On Apr 5, 6:19 pm, skanem...@xxxxxxxx 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
.



Relevant Pages

  • Re: Can Explorer sort order be adjusted?
    ... separate numbers, and the strings are sorted first by first-number, ... Then sorting is by the rest of the character string, ... folder so they know how many digits to use in the numbering, ... The KB article that I gave said the numeric characters are treated as ...
    (microsoft.public.windowsxp.general)
  • Re: Sorting Question for Marshall Barton (Contd)
    ... begin with numbers and strings that begin with characters. ... pad to 8 digits and sort. ... If the string has non-numeric characters in the ...
    (microsoft.public.access.reports)
  • Re: Fibonacci numbers
    ... | Of course there is the question of how to store the number. ... Instead of using characters to represent decimal digits, ... It is easier than dealing with characters, as you don't need to offset ... the way that we write numbers in strings. ...
    (comp.lang.cpp)
  • Re: Best way to check if string is an integer?
    ... lot of strings? ... S.isdigit-> bool ... Return True if all characters in S are digits ...
    (comp.lang.python)
  • Re: extracting numbers and adding
    ... This was published in a prior post - it works on strings up to 99 ... characters and numbers up to 10 digits by extracting numeric portions ...
    (microsoft.public.excel)