0

Python 3 vs Python 2

In python3, why is int(1+2-3*4/5%6) zero whereas in python2 the same evalutes to 1 by substituting for '/' with'//'?

28th Apr 2017, 3:52 PM
Himanshu Rajmane
Himanshu Rajmane - avatar
1 Réponse
+ 8
Python2 used to return integer values when two integers were divided using "/". So 3/2 would mean 1, not 1.5 In Python3 it was effectively changed (changes were done gradually still in Python2 since 2.2) by introducing "//" as floor division operator. This made the division result more predictable and code-dependent. You can read more on the background of this: https://docs.python.org/3/whatsnew/2.2.html#pep-238-changing-the-division-operator
28th Apr 2017, 8:53 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar