The 3.0 version of Python is often called Python 3000, or Py3k for short. This is a major upgrade compared to earlier versions of Python.
In order not to bring too much burden, Python 3.0 was not designed with downward compatibility in mind.
Many programs designed for earlier Python versions cannot run properly on Python 3.0.
In order to take care of existing programs, Python 2.6 is a transitional version that basically uses the syntax and libraries of Python 2.x. It also considers the migration to Python 3.0 and allows the use of some Python 3.0 syntax and functions.
New Python programs are recommended to use the syntax of Python 3.0 version.
Unless the execution environment cannot install Python 3.0 or the program itself uses a third-party library that does not support Python 3.0. Third-party libraries that currently do not support Python 3.0 include Twisted, py2exe, PIL, etc.
Most third-party libraries are working hard to be compatible with Python 3.0 version. Even if Python 3.0 cannot be used immediately, it is recommended to write a program compatible with the Python 3.0 version and then use Python 2.6 or Python 2.7 to execute it.
The changes in Python 3.0 are mainly in the following aspects
The print statement is gone and replaced by the print() function.
Python 2 has ASCII str() type, unicode() is separate, not byte type.
Now, in Python 3, we finally have Unicode (utf-8) strings, and a byte class: byte and bytearrays.
In python 3.x/division no longer does this. For division between integers, the result will also be a floating point number.
Handling exceptions has also changed slightly in Python 3. In Python 3 we now use the as keyword.
The syntax for catching exceptions is changed from except exc, var to except exc as var.
In Python 3, range() is implemented like xrange() so that a dedicated xrange() function no longer exists (in Python 3 xrange() throws a named exception).
In Python 3.x, there is only one way to represent an octal literal, which is 0o1000.
The <> has been removed in Python 3.x. There is only one way of writing !=. Fortunately, I have never been in the habit of using <>
The <> has been removed from Python 3.x. This way of writing `` only allows the use of the repr function. Is this done to make the code look clearer? However, I feel that there are very few opportunities to use repr. It is usually only used during debugging. Most of the time, the str function is still used to describe objects with strings.
Multiple modules have been renamed (according to PEP8)
Py3.X has removed the long type, and now there is only one integer type - int, but it behaves like the 2.X version long
The bytes type has been added, corresponding to the octet string of version 2.X. The method of defining a bytes literal is as follows:
Str objects and bytes objects can use .encode() (str -> bytes) or .decode() (bytes -> str) methods convert each other.
dict's .keys(), .items, and .values() methods return iterators, and the previous iterkeys() and other functions have been abandoned. Also removed is dict.has_key(), replace it with in.
The above is the detailed content of what is python3. For more information, please follow other related articles on the PHP Chinese website!