3 ms·
My favorite python quirk is this expression: -1/3 == -(1/3) Where I would ask people what it evaluates to, and give them the choices: "True", "False", or
by omoikane 4y ago
My favorite python quirk is this expression:
-1/3 == -(1/3)
Where I would ask people what it evaluates to, and give them the choices: "True", "False", or "Python 2 or Python 3?"
- reportgunner 4y agoWhen would this evaluate to False ?
- planede 4y agoApparently it's False in python2. Python2 does integer division that rounds towards negative infinity. It makes the order of operations important in -1/3. (-1)/3 (and hence -1/3) evaluates to -1, and -(1/3) evaluates to 0.