Python2 finishing point of difference with Python3

Small to give in this article where everyone is about the difference between finishing point Python2 and Python3 finishing content, need friends can refer to.
python interpreter default encoding (a distinction to python3 python2)

python2 interpreter default encoding: ASCII
python3 interpreter default encoding: utf-8
input (the difference between two python2 to python3)

python2: name = raw_input ( 'Enter Name')
python3: the INPUT name = ( 'Please enter your name')
output (the difference between python2 and python3 three)

python2: print "hello"
python3: Print ( "Hello")
digital representation (the difference python2 and python3 four)

python2

64-bit machine, the range of -2 63 to 2 63-1

Outside the above range, python automatically converted into long (long)

NOTE: The last digits long (long integer) have a L

python3

All integers are int, not long (long)
integer division (the difference python2 and python3 five)

python2: integer bits can retain
python3: you can keep all the content
range / xrange (difference python2 and python3 six)

python2:
xrange: not created in memory immediately, but at the time of the cycle, while circulating create a
range: to create value in memory immediately all
python3:
only range, equivalent to xrange python2 in the
range: not in memory Creating immediately, but at the time of the cycle, while circulating create
package definition (difference python2 and python3 seven)

python2: folder must have the init _ _ _ .py file
python3: does not require
_ init _ _.py file
dictionary keys / values / items method (difference python2 and python3 eight)

python2: Returns a list by the index value can
python3: returns an iterator, only cycle through the values, not by the value of the index
map / filter (the difference between the nine python2 to python3)

python2: Returns a list created directly value, the index value by
python3: returns an iterator, does not create values directly, through the loop, while circulating create
difference (the difference between ten to python3 python2) (maximum str (string type) difference, priority write this)

python2:
STR types, corresponding to other types of encoded bytes of python3, utf-8 / gbk like
unicode types, corresponding to the string type python3, unicode encoding
python2 no type byte
python3:
STR, strings , unicode coding
python3 type unicode not
inherit object (the difference python2 python3 XI):

class Foo:
  pass
class Foo(object):
  pass
# 在python3中这俩的写法是一样,因为所有的类默认都会继承object类,全部都是新式类。
 
# 如果在python2中这样定义,则称其为:经典类
class Foo:
  pass
 
# 如果在python2中这样定义,则称其为:新式类
class Foo(object):
  pass
 
# 新式类
  # 继承object
  # 支持super
  # 多继承 广度优先C3算法
  # mro方法
# 经典类
  # py2中不继承object
  # 没有super语法
  # 多继承 深度优先
  # 没有mro方法

We recommend the python learning sites, click to enter , to see how old the program is to learn! From basic python script, reptiles, django, data mining, programming techniques, work experience, as well as senior careful study of small python partners to combat finishing zero-based information projects! The method has timed programmer Python explain everyday technology, to share some of the learning and the need to pay attention to small details

Published 34 original articles · won praise 13 · views 40000 +

Guess you like

Origin blog.csdn.net/haoxun06/article/details/104504709