Very basic question
Sion Arrowsmith
siona at chiark.greenend.org.uk
Tue Dec 23 06:23:16 EST 2008
Sengly <Sengly.Heng at gmail.com> wrote:
>I would like to calculate a string expression to a float. For example,
>I have ('12/5') and I want 2.4 as a result. I tried to use eval but it
>only gives me 2 instead of 2.5
py> from __future__ import division
py> print eval('12/5')
2.4
py> print eval('12//5')
2
Or switch to 3.0 which gives you this behaviour without the __future__
import.
--
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
More information about the Python-list
mailing list