[Tutor] strings and int()
jadrifter
jadrifter at gmail.com
Thu Jan 15 01:37:39 CET 2009
Try eval("2*3")
On Thu, 2009-01-15 at 10:14 +1000, Mr Gerard Kelly wrote:
> If you have a string "6", and you do int("6"), you get the number 6.
>
> But if you have a string "2*3" and you do int("2*3") you get a name error.
>
> How do you take an expression in a string, and evaluate the expression
> to get a number?
>
> I want to be able to turn the string "2*3" into the number 6.
>
> thanks
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list