On Jul 10, 2008, at 12:54 AM, Gopal Ghosh wrote:


*********************
>>> 7/3
2
>>> 7/-3
-3
>>> 3/7
0
>>> # again reapting the questions with one more decimal place
>>> 7.0/3
2.3333333333333335
>>> 7.0/-3
-2.3333333333333335
>>> 3.0/7
0.42857142857142855
>>> # why it is not showing the exact values in the previous cases
>>>

Dividing Integer by an integer will give you Integer
Dividing Integer by a float or a float by an integer will give a float.
See this: http://docs.python.org/ref/binary.html

However this behaviour will change to a less "surprising" 3/4 returning 0.75 as one would expect in python 3.0 See: http://www.comp.leeds.ac.uk/nde/papers/ teachpy3.html#unsurprising-arithmetic

-PG
http://pradeepgowda.com

_______________________________________________
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers

Reply via email to