Here's a summary of the differences between Python2 and Python3:
A. input
Using the input_raw () function in Python2
Using the input () function in Python3
Two. Output
Python2: Printstatement , the statement means that you can directly follow what you want to print, if you follow a tuple object, print directly
Python3: Theprint function , which functions as if it had to be bracketed to call--------print ()
Three. Encoding
Python2: Default encoding ASCII
Python3: Default encoding utf-8
Four. String type
Version |
Python2 |
Python3 |
byte string |
Str |
bytes |
Text string |
Unicode |
Str |
Five. Division
The result in Python2 is shaping, and floating-point types are in Python3.
Six. Import
Package Import order in Python2: standard library-relative pour (i.e. current directory)-Absolute import (Sys.path)
Package Import order in Python3: standard library-Absolute import (if you want to import relative, use from. Moudel)
Seven. Class
The default class in Python2 is a legacy class, and you need to explicitly inherit the modern Class (object) to create a modern class.
The old class is completely removed in Python3, all classes are modern, but you can still explicitly inherit the object class.
Eight. Renaming the module
Python3 |
Python2 |
Configparser |
Configparser |
Filter |
Itertools.ifilter |
Input |
Raw_input |
Map |
Itertools.imap |
Range |
Xrange |
Functools.reduce |
Reduce |
Socketserver |
Socketserver |
Zip |
Itertools.izip |
Nine. Module merging
Stringio and Cstringio in Python2 are merged into IO in Python3
The pickle and Cpickle in Python2 are merged into Pickle in Python3.
Urllib, Urllib2, and Urlparse in Python2 are merged Python3 in Urllib
10. Dictionaries
Keys, values, and items in the Dict class in Python2 return a list object, Iterkeys, Itervalues, and Iteritems return the builder object.
Python3 removes list, returns only one generator object, preserves only the view (builder), but the method is named: Keys, values, and items.
The difference between Python2 and Python3