On Apr 30, 7:56 pm, MooMaster <[EMAIL PROTECTED]> wrote: > N00b question alert! I did a search for isdigit() in the group > discussion, and it didn't look like the question had been asked in the > first 2 pages, so sorry if it was... > > The manual documentation says: > "isdigit( ) > > Return true if all characters in the string are digits and there is at > least one character, false otherwise. > For 8-bit strings, this method is locale-dependent. " > > So it makes sense that something like 5.6 would return false. But what > if we want to make sure that our string is a valid number, ie decimals > included? > > I know how to write a regexp or method or whatever to do this, my main > question is *why* something like an isNumber() method is not baked > into the class. Does such functionality exist somewhere else in the > standard library that I'm just missing?
A string s is a valid number if float(s) does not raise a ValueError. -- http://mail.python.org/mailman/listinfo/python-list