Python2 vs Python3: str

来源:互联网 发布:青岛衣知她有限公司 编辑:程序博客网 时间:2024/06/14 16:44

Python2 vs Python3: str

Python2 中存在2种str

>>> a='123'>>> b=u'123'>>> type(a)<type 'str'>>>> type(b)<type 'unicode'>

Python3中只存在1种str

>>> a='123'>>> b=u'123'>>> type(a)<class 'str'>>>> type(b)<class 'str'>>>> b='\u8bf7'>>> type(b)<class 'str'>

Python3新增了一种类似bytes

>>> b=b'\u8bf7'>>> b.decode('unicode-escape')'请'>>>>>> type(b)<class 'bytes'>
原创粉丝点击