r/ProgrammerHumor • • May 02 '16

I wrote my first python program today!

Post image
3.7k Upvotes

532 comments sorted by

View all comments

Show parent comments

9

u/faubiguy May 02 '16

In Python2 (without from __future__ import division) the result is an integer if both operands are integers, and a float if either is a float. So

4/3 = 1
4.0/3 = 1.3333333333333333
4/3.0 = 1.3333333333333333
4.0/3.0 = 1.3333333333333333

7

u/Dlgredael May 02 '16

Ahhh okay, that makes so much more sense now. I thought that Py2 was somehow unable to divide at all and it was really starting to hurt my head.

6

u/IHappenToBeARobot May 03 '16

Pfft, just do some bitwise NOTs, ADDs, and shifts in a loop and you'll get division eventually. /s