Nov-26-2020, 12:03 PM
(Nov-26-2020, 10:12 AM)Chirumer Wrote: So I changed the question from "why // changed" to "why // works the way it does"
If you follow the documentation then you find:
- Documentation > The Python Language Reference > 6. Expressions > 6.1. Arithmetic Conversions:
Quote:When a description of an arithmetic operator below uses the phrase “the numeric arguments are converted to a common type”, this means that the operator implementation for built-in types works as follows:
Some additional rules apply for certain operators (e.g., a string as a left argument to the ‘%’ operator). Extensions must define their own conversion behavior.
- If either argument is a complex number, the other is converted to complex;
- otherwise, if either argument is a floating point number, the other is converted to floating point;
- otherwise, both must be integers and no conversion is necessary.
On the same page, under 6.7. Binary arithmetic operations you will find:
Quote:The / (division) and // (floor division) operators yield the quotient of their arguments. The numeric arguments are first converted to a common type. Division of integers yields a float, while floor division of integers results in an integer; the result is that of mathematical division with the ‘floor’ function applied to the result. Division by zero raises the ZeroDivisionError exception.
It is good practice to read documentation. Even more, if you follow python.org advice then you even keep some stuff under the pillow (documentation)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.