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")

 

相关文章:

  • 2021-06-07
  • 2021-12-27
  • 2021-09-22
猜你喜欢
  • 2021-11-30
  • 2021-07-06
  • 2021-11-01
  • 2021-09-27
相关资源
相似解决方案