python3 vs python2

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值