Python2.x和Python3.x的区别

  1.xrange

python2.x中,比如使用rang(100),会给分配100的内存保存100个数(执行效率和内存)

python3.x中,使用xrange,空间复杂度是o(1),要一个数给一个数。

2.print

python2.x中,print不用加括号

python3.x中,print要加括号

3.异常

python2.x中

a=10
b=0
try:
    c=a/b
    print c
except ZeroDivisionError,e:
    print e.message
print "done"

python3.x中

a=10
b=0
try:
    c=a/b
    print(c)
except ZeroDivisionError as e:
    print(e.message)
print("done")
原文地址:https://www.cnblogs.com/chenyang920/p/7838412.html