Idenfity numbers in variables

Duncan Booth duncan.booth at invalid.invalid
Mon Oct 20 19:58:27 CEST 2008

Lie Ryan <lie.1296 at> wrote:

> That's the job of regular expression: 'import re'
> numbered_atom = re.compile('[A-Z][a-z]?[0-9]+')
> if numbered_atom.match('C10'):
>     # this is a numbered atom
> if numbered_atom.match('C'):
>     # this WON'T match
> read more about regular expression on the web (hint: python share the 
> same re syntax with many other languages, php, javascript, grep, etc)

Or simply:

if atom[-1].isdigit():
   # this is a numbered atom
   # this isn't

More information about the Python-list mailing list