Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion How to check if a string "is" an int?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dave Hansen  
View profile  
 More options Dec 21 2005, 6:17 pm
Newsgroups: comp.lang.python
From: Dave Hansen <i...@hotmail.com>
Date: Wed, 21 Dec 2005 17:17:16 -0600
Local: Wed, Dec 21 2005 6:17 pm
Subject: Re: How to check if a string "is" an int?
On 21 Dec 2005 14:36:32 -0800 in comp.lang.python, Paul Rubin

<http://phr...@NOSPAM.invalid> wrote:
>There is a third choice which is the natural and obvious one: have the
>function do what its name indicates.  Return true if the arg is a
>digit and false otherwise.  If iterating over the whole string is
>useful (which it may be), then the function should have been named
>differently, like .isdigits instead of .isdigit.

Following your logic to its conclusion, had the name isdigits been
chosen, '1'.isdigits() should return False.  It's only one digit, not
more than one, as the plural would imply.

I, for one, don't see any utility in the dichotomy.  We only need
(should only have) one function.  I do agree that isdigits might have
been a better name, but we're stuck with isdigit for hysterical
raisins.  And it's logical that string functions work over a string
rather than its first character.

>FWIW, I've usually tested for digit strings with re.match.  It never
>occurred to me that isdigit tested a whole string.  

Someone's been trotting out that old jwz chestnut about regular
expressions and problems...  Not that I agree with it, but ISTM that
regular expressions are vast overkill for this problem.

Regards,
                                        -=Dave

--
Change is inevitable, progress is not.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.