1. The performance

Py3.0 runs PyStone Benchmark 30% slower than Py2.5. Guido believes that Py3.0 has a lot of room for optimization, with good results for string and integer operations. Py3.1 performance is 15% slower than Py2.5 and there is still a lot of room for improvement.

2. The coding

The py3. X source file uses UTF-8 encoding by default, which makes the following code legal: >>> China = ‘China’ >>>print(China) China

3. Grammar

1) <> <> Repr (); repr(); repr(); repr(); repr(); Using Noclocal x, the peripheral (non-global) variable 6 can be directly assigned to remove the print statement and add the print() function to achieve the same function. The exec() function changes the behavior of the sequential operator, such as x

9) Remove the tuple parameter unpacking. Cannot def(a, (b, c)):pass defines functions in this way. 11) Added binary literals and the bin() function

12) Extended iterable unpacking. In Py3.X, a, b, *rest = seq and *rest, a = seq are both legal, requiring only two things: rest is a list object and SEQ is iterable. 13) The new super() can no longer pass arguments to super(),

New metaclass syntax: class Foo(*bases, ** KWDS): pass The usage is the same as the function decorator:

4. Strings and bytes

1) There is only one string type, STR, but it is almost the same as the 2.x version of Unicode.

2) For bytes, see item 2 of “Data types.

5. Data types

1) Py3.X has removed long and now has only one integer — int, but it behaves just like long in 2.X. 2) We have added bytes, which correspond to octet strings in 2.X. STR objects and bytes objects can be converted to each other using the.encode() (STR -> bytes) or.decode() (bytes -> STR) methods.

Dict’s.keys(),.items, and.values() methods return iterators, and the previous iterkeys() functions are deprecated. Also dropped is dict.has_key(), replaced with in

6. Object oriented

Abstraact Base Classes (ABCs) 2) Container classes and iterator classes are ABCs, so there are many more types in the Cellections module than in Py2.5. >>> import collections >>> print(‘\n’.join(dir(collections))) Callable Container Hashable ItemsView Iterable Iterator KeysView Mapping MappingView MutableMapping MutableSequence MutableSet NamedTuple Sequence Set Sized ValuesView __all__ __builtins__ __doc__ __file__ __name__ _abcoll _Itemgetter _sys defaultdict deque In addition, numeric types are abCs-ized. See PEP 3119 and PEP 3141 for both points. 3) Rename the iterator’s next() method to __next__() and add a built-in function next() to call the iterator’s __next__() method. 4) Add @abstractMethod and @abstractProperty decorators. It is easier to write abstract methods (properties).

Abnormal 7.

1) So exceptions inherit from BaseException, Message attribute 3) Replace raise Exception(args) with raise Exception, args syntax 4) Catch the syntax change of the Exception, The AS keyword was introduced to identify exception instances

5) Exception chain, because __context__ was not implemented in 3.0A1

8. Module changes

1) Remove the cPickle module and use the pickle module instead. Eventually we will have a transparent and efficient module. Audiodev, Bastion, BsdDB185, exceptions, LinuxAudiodev, MD5, MimeWriter, Mimify, Popen2, Rexec, Sets, SHA, Stringold, strop, SunAudiodev, Timing, and XMLlib modules 4) Removed the BSDDB module (distributed separately, available from www.jcea.es/programacio… Get) 5) New module removed 6) os.tmpnam() and os.tmpfile() functions moved under tmpfile module 7) Tokenize module now works with bytes. The main entry point is no longer Generate_tokens, tokenize.tokenize()

9. Other

>>> list(range(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

2) Bytes objects cannot hash and do not support b.power (), b.trip (), and b.split() methods. For the latter two, however, we can use b.trip (b ‘\n\t\r \f’) and b.split(b ‘ ‘) to achieve the same purpose. 3) Zip (), map(), and filter() all return iterators. The apply(), callable(), coerce(), execfile(), reduce(), and reload () functions have all been removed. It is now possible to use hasattr() instead of callable(). Hasattr () syntax is as follows: hasattr(string, ‘__name__’)

Lowercase and.uppercase are removed and TypeError is raised if x < y is not comparable. The 2. X version is returning pseudo-random Boolean values of 6) __getslice__ series members are deprecated. A [I :j] is converted to A. __getitem__(slice(I, j)) or __setitem__ and __delitem__ call 7) file class is deprecated depending on the context



If you are interested in Python development technology, please add QQ group 705673780 to study and discuss with each other.