您的位置:首页 > 编程语言 > Python开发

python2与python3区别汇总

2016-12-29 11:14 393 查看
Remove dict.iteritems(), dict.iterkeys(), and dict.itervalues().

Instead: use dict.items(), dict.keys(), and dict.values() respectively.

python 3.x中urllib库和urilib2库合并成了urllib库

其中urllib2.urlopen()变成了urllib.request.urlopen()

urllib2.Request()变成了urllib.request.Request()

需要import urllib.request 而不是只引用import urllib,否则会出现A ttributeError: ‘module’ object has no attribute ‘reques

在python2里面,u表示unicode string,类型是unicode, 没有u表示byte string,类型是 str。

在python3里面,所有字符串都是unicode string, u前缀没有特殊含义了。

r都表示raw string. 与特殊字符的escape规则有关,一般用在正则表达式里面。

r和u可以搭配使用,例如ur”abc”。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python