python3 vs python2

发布时间:2020-06-12 00:38:15 作者:hasdfsdf
来源:网络 阅读:270

一、print,在python3中已经是函数

>>> import sys
>>> print("fatal error",file=sys.stderr)
fatal error
>>> fp=open(r"d:\\a.txt",'w')
>>> print("python3",file=fp)
>>> fp.close()
>>> print("There are <", 2**32, "> possibilities!", sep=" ") 默认空格符为分隔符
There are < 4294967296 > possibilities!
>>> print("There are <", 2**32, "> possibilities!", sep="") 自定义,不用空格分开
There are <4294967296> possibilities!
>>> 

二、python3中是unicode码,而python2中是ascii码,可以避免中文的编码困扰

>>> import sys
>>> print(sys.getdefaultencoding())
utf-8
>>> "中文"
'中文'

在python2.7中

>>> import sys
>>> sys.getdefaultencoding()
'ascii'
>>> "中文"
'\xd6\xd0\xc\xc4'

三、定义变量更灵活

>>> a,*b,c= range(5)
>>> a,b,c
(0, [1, 2, 3], 4)

四、某些库改名了

Old Name New Name

_winreg winreg

ConfigParser configparser

copy_reg copyreg

Queue queue

SocketServer socketserver

markupbase _markupbase

repr reprlib

test.test_support test.support

推荐阅读:
  1. Python3 与 Python2共存
  2. python3怎么运行

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python3变化

上一篇:今天启用这个标签

下一篇:一步一步教你 JS、控件封装成类库

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》