[Edu-sig] new python // and /

Guido van Rossum guido at python.org
Fri May 26 19:02:15 CEST 2006


On 5/26/06, Andrew Harrington <aharrin at luc.edu> wrote:
> As I gear up to write or translate lessons for Crunchy Frog, I would
> like feedback on one general issue:
> //  -- the new integer division operator.

It's hardly new; it was introduced in 2.2.

> // is already legal in Python 2.4, though / still means the same thing
> for integers.  That is to change in Python 2.5, that is already in alpha
> 2:
> / as integer division will able to be set to mean the old operator or
> always mean real division (I forget which is the default in 2.5).

Where did you get this? / won't change its meaning until 3.0. Ever
since 2.2 you can force it to mean real division by using "from
__future__ import division".

> I think this is an excellent change in Python.  I would encourage using
> // for integer division in all newly written lessons.

Right. We've been encouraging this ever since 2.2.

> There is the
> issue in 2.4 that you still have to go through an extra cast if you want
> real division,
> x = 5
> y = 3
> real_quotient = float(x)/y
>
> but there is nothing for that at the moment

Unless you want to promote the __future__ statement above. But that's
questionable for newbies -- it's better to teach the current language.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Edu-sig mailing list