Page MenuHomeDevCentral

Python 2 and 3 behaviors related to divide and integer floor.
ActivePublic

Authored by dereckson on May 22 2015, 12:27.
dereckson@tasacora:~/workspace/repositories/tasacora-experimental/core/tests (master) $ python2
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 3/2
1
>>>
dereckson@tasacora:~/workspace/repositories/tasacora-experimental/core/tests (master) $ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 3/2
1.5
/home/dereckson ] python3
Python 3.3.5 (default, Dec 3 2014, 04:17:16)
[GCC 4.2.1 Compatible FreeBSD Clang 3.3 (tags/RELEASE_33/final 183502)] on freebsd10
Type "help", "copyright", "credits" or "license" for more information.
>>> int(1.5)
1
>>>

Event Timeline

dereckson changed the title of this paste from untitled to Python 2 and 3 behaviors related to divide and integer floor..
dereckson updated the paste's language from autodetect to autodetect.
dereckson added a project: Tasacora.
dereckson added a subscriber: rama.

@rama int(length / 2) is evaluated at 1 in both Python 2 and 3.

The difference is the argument: if length = 3, this will execute int(1) and int(1.5).