新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

python3vspython2

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

在做网站、成都网站建设中从网站色彩、结构布局、栏目设置、关键词群组等细微处着手,突出企业的产品/服务/品牌,帮助企业锁定精准用户,提高在线咨询和转化,使成都网站营销成为有效果、有回报的无锡营销推广。创新互联专业成都网站建设十年了,客户满意度97.8%,欢迎成都创新互联客户联系。

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


网页标题:python3vspython2
URL分享:http://www.wjwzjz.com/article/gdcesc.html
在线咨询
服务热线
服务热线:028-86922220
TOP