码迷,mamicode.com
首页 > 编程语言 > 详细

python3变化

时间:2019-05-28 15:28:35      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:open   python   encoding   imp   conf   config   close   tde   默认   

一、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

python3变化

标签:open   python   encoding   imp   conf   config   close   tde   默认   

原文地址:https://blog.51cto.com/5918475/2401309

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!