[Tutor] string to number

Andrei Kulakov ak@silmarill.org
Tue, 16 Apr 2002 17:51:22 -0400


On Tue, Apr 16, 2002 at 02:23:14PM -0500, Jordan, Jay wrote:
> I have a list containing multiple strings which are numbers. [209, 30, 50,
> 123, 40, ...etc]
> 
> I want to use my list but perform numerical operations on the contents but
> it wont let me use INT and the ATOL function keeps comming up as undefined
> even though I have IMPORT STRING at the top of my project. Is there another
> better way to take a string and make it a number?
>

Python 2.1.1 (#1, Apr  6 2002, 13:34:31) 
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> l = ["209", "30", "50"]
>>> l = [int(x) for x in l]
>>> l
[209, 30, 50]

> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org