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

4. Strings and Bytes

Joannah Nanjekye
(1)
Kampala, Uganda
 
Python 3 created a clear distinction between bytes and text, as opposed to Python 2 that uses the str type for both text and bytes. Python 2’s idea of the str type led to a scenario where code worked for either type of data, or sometimes none. On the other hand, Python 3 requires that you care about when you are using text (as compared to binary data). This chapter describes how to absorb these differences in a single code base that can run in both Python versions. First, let’s look at these differences.

Text and Binary Data

In Python 2, any string that appears in normal quotes are ...

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.