Getting a number out of a string

jepler at unpythonic.net jepler at unpythonic.net
Tue Sep 27 14:26:17 EDT 2005


You can index into a string:
>>> s = '06897'
>>> s[2]
'8'

You can also turn each character into an integer, in various ways:
>>> [int(c) for c in s]
[0, 6, 8, 9, 7]
>>> map(int, s)
[0, 6, 8, 9, 7]

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050927/10bcd2f3/attachment.sig>


More information about the Python-list mailing list