前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python3 vs python2

python3 vs python2

作者头像
py3study
发布2020-01-06 10:15:17
3840
发布2020-01-06 10:15:17
举报
文章被收录于专栏:python3python3python3

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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-27 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档