[Tutor] eval and floating point
Alan Gauld
alan.gauld at btinternet.com
Thu Jan 15 13:08:39 CET 2009
"Mr Gerard Kelly" <s4027340 at student.uq.edu.au> wrote
> I've noticed that the eval() function gives an integer, so
> eval("3/2")
> gives back 1. float(eval("3/2")) doesn't seem to work, any way to
> get a
> floating point number back with eval()?
Move the float inside the eval:
eval("float(3/2)")
It's nothing to do with eval but with Python. eval just asks the
interpreter to evaluate the string. Which is why you hardly ever
need to use eval, you can usually work with the string in your
own code and execute it that way.
Alan G
More information about the Tutor
mailing list