How to print a number as if in the python interpreter?

Peng Yu pengyu.ut at gmail.com
Sat Jul 7 00:38:38 CEST 2012


Hi,

In [2]: sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
Out[2]: 0.9999999999999999

In ipython, I got the above output. But I got a different output from
"print". Is there a way to print exact what I saw in ipython?

~/linux/test/python/man/library/math/fsum$ cat main.py
#!/usr/bin/env python
print sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
~/linux/test/python/man/library/math/fsum$ ./main.py
1.0

Regards,
Peng



More information about the Python-list mailing list