A pretty dumb newbie question

Luke LLoeffler at home.com
Mon Dec 3 21:40:50 EST 2001


oops. sorry.

You question is really why isn't 1/2 = .5

/ is floor division in python.
1.0/2 works as expected or 1/2.0... or 1 * 1.0/ 2

In 3.0, / will be 'normal' division and // will be floor

with 2.2 you can "from __future__ import division" to make / behave as 
expected.  (or just multiply by 1.0 to convert to a float before dividing.)

2**.5 will work as expected.  2**0 is obviously 1.

Luke




More information about the Python-list mailing list