Home >Backend Development >Python Tutorial >Which version is newer, python2 or python3?
Python2 or Python3?
py2.7 is the last version of the 2.x series. Development has been stopped and no new features will be added. End of support in 2020.
All the latest standard library updates and improvements will only appear in version 3.x.
Python 3.0 was released in 2008, and 2.7 is the final version of 2.X and continues to be maintained.
Guido van Rossum's idea is not to provide backward compatibility with version 2.7.
The most significant improvement of Python 3.x is better Unicode support, and all text strings are Unicode by default. In Python 2.x, an error will be reported when writing Chinese directly, but in Python 3, Chinese can be written directly.
From the perspective of open source projects, the proportion of supporting py3 has been greatly increased. Well-known projects generally support py2.7 and py3.
py3 is more standardized and unified than py2, and unnecessary keywords are removed.
Python3.x continues to improve.
Main changes in Python3.x
Coding methods and performance
Faster running efficiency
The default source file encoding ASCII has been changed to UTF-8, and the coding=utf-8 added before the previous file is no longer needed
The processing of unicode has been significantly improved, and the efficiency has been significantly improved
Data types and basic operations
int and long are unified and unified into int
True, False, and None are all keywords
Must use b'...' to represent binary data, you can use u'..' to represent a string, or a string without adding u
Remove the <> inequality sign and use "! =" indicates the inequality sign relationship
Adjust the usage of the division symbol '/', only return floating point numbers, to return integers use "//"
has a single str type, its type is equivalent to 2.x's unicode, all strings in 3.x are unicode
range and dict changes
In 2.x, range will be different from xrange Create a list. It often appears in for loops, dictionaries, and lists. However, xrange was renamed range in 3.x. Using xrange in 3.x will trigger an error. At the same time, range returns an iterable object instead of a list. If you want to get a list data from the range result, you must use list(range(5))
dict.iterkeys(), dict.itervalues (), dict.iteritems() is replaced by keys() and values() and items(). Their return results are iterable objects similar to sets, rather than lists of key-value pairs. Thus, the set operation can be performed on the key and value entries without copying them.
Iterator
range returns an iteration object in python3, not a list , save memory to the maximum extent
zip(), map(), filter(), key(), value() all return iterable objects
The above is the detailed content of Which version is newer, python2 or python3?. For more information, please follow other related articles on the PHP Chinese website!