Converting Strings to Integers in Python

Fredrik Lundh effbot at telia.com
Tue Feb 22 18:19:01 EST 2000


Lenny Self <lenny at squiggie.com> wrote:
> I am new to Python and programming in general.  I was wondering if someone
> might help me with the proper syntax for converting a string or a portion
of
> a string into an integer.

I'm pretty sure this is explained in the tutorial,
but alright:

>>> s = "123"
>>> s
'123'
>>> int(s)
123
>>> int(s[1:2])
2

for more info, see the docs (www.python.org)

hope this helps!

</F>





More information about the Python-list mailing list