Python2.x and 3.x versions difference Ⅲ

Octal literal representation

Octal number must be written 0o777, the original form of 0777 can not be used; binary must be written 0b111.

Added a bin () function is used to convert a number into a binary integer https://www.xuanhe.net/ string. Python 2.6 has support for both syntax.

In Python 3.x, the octal literal only one way, that is 0o1000.

python 2.x

 

 python 3.x

 

Inequality operators

Python 2.x is not written in two equal! = And <>

Python 3.x removed in <> Only! = Way to write, but fortunately, I never use <> habits


Removed the expression `` repr

Anti Python 2.x marks `` repr function corresponding to the role of

Python 3.x removed in `` The wording, only allows the use repr function, purpose of doing so is to make the code look more clear it? But I feel a little chance repr, generally only used when debug, and most of the time or use string str function to describe the object.

 

 

A plurality of modules are renamed (according PEP8)

 

 

StringIO module is now incorporated into the new io module. new, md5, gopherlib modules are deleted. Python 2.6 has support for the new io module.

httplib, BaseHTTPServer, CGIHTTPServer, SimpleHTTPServer, Cookie, cookielib http is incorporated into the package.

Canceled the exec statement, only the exec () function. Python 2.6 has support exec () function.


5. Data Type

1) Py3.X removed long type, now there is only one integer --int, but it behaves like the long version 2.X

2) Type Added bytes corresponding to eight strings version 2.X, a definition of the literal bytes as follows:

 

 str bytes objects and objects may be used .encode () ( str -> bytes ) or .decode () ( bytes -> str ) interconversion methods.

 

 3) dict the .keys () ,. items and .values ​​() method returns an iterator, but before the iterkeys () function and the like are discarded. Meanwhile removed as well dict.has_key (), replace it with in it.

Guess you like

Origin www.cnblogs.com/danjiu/p/12039903.html