Question about Py 2.2.x division operator

Tim Peters tim.one at comcast.net
Sun Dec 29 15:34:12 EST 2002


[ahimsa]
> I am using Python 2.2c1

Get 2.2.2.  2.2c1 was a release candidate for 2.2 final, and had a useful
life of just a few dayes.

> and have a query regarding the use of division operators.
> I haven't seen this covered previously, but if it has, my apologies
> for redundancy.

All the detail you can eat can be found here:

    http://www.python.org/peps/pep-0238.html

> I understand that pre-2.2 the '/' would only perform 'floor' division
> and truncate the remainder

Provided that both operands were of integer types, yes.  If either argument
is complex, you got (and get, and always will get) a complex result instead.
If neither argument is complex, but at least one is a float, you got (and
get, and always will get) a float result instead.

> -- e.g. 7 / 4 == 1

Right.  That's changing (see the link above).

> -- but that with 2.2 '//' would be used for floor division

Should be used.  Nothing about the meaning of '/' has changed yet, but the
meaning of integer / integer *will* change.

> and '/' would be used for true division -- e.g. 7 // 4 == 1 while 7 / 4
> == 1.75.

Eventually, but not yet.  Not even in Python 2.3.

> When I try this I can get the fraction by using real numbers
> (i.e. 7.0 / 4 == 1.75)

Yes, and you always will.  Only the meaning of integer / integer will
change.  7.0 is a float literal (not an integer literal).

> *without* importing the future module, so what are the advantages of
> importing the division component of the 'future' module unless I was
> only going to be using integers?

I didn't understand the question, but I bet reading the PEP will answer it
anyway <wink>.





More information about the Python-list mailing list