© Joannah Nanjekye 2017
Joannah NanjekyePython 2 and 3 Compatibilityhttps://doi.org/10.1007/978-1-4842-2955-2_2

2. Numbers

Joannah Nanjekye
(1)
Kampala, Uganda
 
When implementing Python 2 and Python 3 compatibility in a single code base, division won’t truncate unless double slashes are used, or __future__ importation to division is done. All integers are long; there are no short integers because long() is gone; octal constants must start with 0o (zero-oh); and there are syntax changes to note in the integer inspection. Let’s discuss each of these in detail.

Inspecting Integers

In Python 3, there are no long integers; therefore, integer types are checked against type int; for example:
Download Numbers/inspectionpy3.py
y = 3
if isinstance(y, int):

Get Python 2 and 3 Compatibility: With Six and Python-Future Libraries now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.