[Tutor] Converting string or list to sum

orbitz at ezabel.com orbitz at ezabel.com
Thu Jan 29 14:47:18 EST 2004


The easiest way out is probably to use eval.

>>> eval('2+1')
3


if you have a list, however, you will just create a list using that.


On Thu, 29 Jan 2004 19:14:23 +0000
Iain <python at cairnlin.co.uk> wrote:

> If I have a sum as a string (e.g. '2+3') or in a list (e.g. [2,'+',3]), how 
> can I get the result of the sum?
> 
> Thanks
> 
> Iain.
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list