我对python相当陌生,我很欣赏它是一种动态语言。在我第一次编写python代码的大约30分钟内,我发现bytes
类型的行为有点奇怪(至少可以这么说):
a = bytes()
print type(a)
// prints: <type 'str'>
在这里试试:
http://ideone.com/NqbcHk
现在,docs说strings
和{}的行为非常相似,除了.format
和{}但我没想到它们是同一类型的。我要确保的是,我可以处理代码中的实际字节,并且不会发生强制/编码/解码。在
怎么回事?在
Tags:
你看到的是python3文档。在Python2中,
bytes
是str
的别名,添加它是为了更容易地编写兼容代码(python2的str
是一个字节字符串,而在python3中,str
是python2中称为unicode
)的别名。在有关详细信息,请参见What’s New In Python 3.0。在
在python3.x中,}的一个简单别名。在
bytes
类型是新的。在python2.x中,作为兼容性填充程序,bytes
是{请在此处阅读更多信息:https://docs.python.org/2/whatsnew/2.6.html#pep-3112-byte-literals
相关问题 更多 >
编程相关推荐