How to check if a string "is" an int?
Erik Max Francis
max at alcyone.com
Wed Dec 21 16:58:01 EST 2005
Steven D'Aprano wrote:
> In that case, the name is misleadingly wrong. I suppose it is not likely
> that it could be changed before Python 3?
Why?
The primary purpose of the .isdigit, etc. methods is to test whether a
single character has a certain property. There is, however, no special
character data type in Python, and so by necessity those methods must be
on strings, not characters.
Thus, you have basically two choices: Have the methods throw exceptions
for strings with a length different from one, or have them just iterate
over every character in a string. The latter is clearly a more useful
functionality.
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Make it come down / Like molasses rain
-- Sandra St. Victor
More information about the Python-list
mailing list