[英]Behavior change of bytes from py2 to py3
Python 3 bytes
构造函数采用一个可选的int
参数,该参数指定要输出的字节数。 使用该构造函数将所有字节初始化为0( \\x00
),因此bytes(1) == b'\\x00'
。
Python 2 bytes
构造函数与str
相同,因此仅将其参数字符串化:
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> bytes is str
True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.