Python 2 v.s. Python 3

Python 2 and Python 3 are mostly the same during our discussions. However there are some differences if you explore further. During this semester, we base our discussions and exercises on Python 3. We highlight some main differences here for your reference. To read further, you can click here

pip and pip3

If you want to install modules for Python3, please use pip3 . To install in user mode, you can use

pip3 install --user {name-of-the-module}

syntax of print

Python 2’s print statement has been replaced by theprint()function, meaning that we have to wrap the object that we want to print in parantheses.

Python 2 doesn’t have a problem with additional parantheses, but in contrast, Python 3 would raise aSyntaxErrorif we called the print function the Python 2-way without the parentheses.

However, if we have multiple objects inside the parantheses, we will create a tuple, sinceprintis a “statement” in Python 2, not a function call.

str, bytes, encoding and decoding

Python 2 has ASCIIstr()types, separateunicode(), but nobytetype.

Now, in Python 3, we finally have Unicode (utf-8)strings, and 2 byte classes:byteandbytearrays.

How to set up Python 2.7 and Python 3 at the same time on your Mac OSX?

You can follow the steps in this Link to set up both of them.

results for ""

    No results matching ""