Appendix B. Differences Between Python 2 and 3

Throughout the book, we have mentioned several differences between Python 2 and Python 3. The book uses Python 2, but we also want you to know how to recognize Python 3 code and make your code compatible with Python 3 if you want to. This appendix only talks about the Python 2 to 3 differences in the parts of Python that we have covered in this book. (For example, Python 3 handles Unicode strings differently, but because we didn’t talk about Unicode, we won’t talk about the Python 3 Unicode changes.)

With that in mind, here are some of the ways Python 3 is different from Python 2.

print

In Python 3, print is a function. That means instead of writing

print "Hello, World!"

you need to write

print ...

Get Hello World! Second Edition 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.