Python 2和Python 3的主要区别

Coding Alan 7年前 (2017-10-08) 4751次浏览 0个评论 扫描二维码

Python 2和Python 3的主要区别

  1. Python 2和Python最大的区别就是字符编码上的区别,通常在Python 2的文件头都需要声明为UTF-8编码:

因此对于Python 2的中文符需要编码(先转为Unicode再进行encode)

而Python中则直接采用了Unicode编码,无需进行转码

SyntaxError: Missing parentheses in call to ‘print’
在Python 3中print后需添加括号进行打印输出

NameError: name ‘xrange’ is not defined
Python 2下的xrange在Python 3中使用range

AttributeError: ‘dict’ object has no attribute ‘itermvalues’
Python 3对于原Python 2下的iteritems, iterkeys, itervalues一律去除iter

喜欢 (0)
[]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址