[Tutor] how to tell if strings have numbers in them

Deirdre Saoirse deirdre@deirdre.net
Thu, 4 Jan 2001 10:32:28 -0800 (PST)

On Thu, 4 Jan 2001, Remco Gerlich wrote:

> Someone else already posted this, but not many people seem aware of
> it. (I know I wasn't). In Python 2.0, strings have the useful
> isdigit() method, that tests if all characters in the strings are
> digits:

Actually, it's also in 1.6. I don't remember quite when it was introduced.

Under 1.6, dir(x) gives:

['capitalize', 'center', 'count', 'endswith', 'expandtabs', 'find',
'index', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join',
'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust',
'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase',
'title', 'translate', 'upper']

> >>> x="123"
> >>> x.isdigit()
> 1

_Deirdre      *      http://www.sfknit.org      *      http://www.deirdre.net 
"We have an open door policy." -- Sheridan
"And an open airlock policy." -- Ivanova