Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 什么';s“中的0”;b中的0,0,0,0表示字节(4)中的b”;_Python 3.x - Fatal编程技术网

Python 3.x 什么';s“中的0”;b中的0,0,0,0表示字节(4)中的b”;

Python 3.x 什么';s“中的0”;b中的0,0,0,0表示字节(4)中的b”;,python-3.x,Python 3.x,我正在学习字节和文本 In [179]: [b for b in bytes("text", "utf-8")] Out[179]: [116, 101, 120, 116] 我能理解这一点,因为数字匹配ascii码中的每个字母 In [185]: [ord(char) for char in "text"] Out[185]: [116, 101, 120, 116] 说到数字 In [188]: [b for b in bytes(4)] Out[188]: [0, 0, 0, 0] I

我正在学习字节和文本

In [179]: [b for b in bytes("text", "utf-8")]
Out[179]: [116, 101, 120, 116]
我能理解这一点,因为数字匹配ascii码中的每个字母

In [185]: [ord(char) for char in "text"]
Out[185]: [116, 101, 120, 116]
说到数字

In [188]: [b for b in bytes(4)]
Out[188]: [0, 0, 0, 0]
In [189]: bytes(1)
Out[189]: b'\x00'
为什么字节(4)中只有0,那么
b'\x00'
bytes()
中的
x
ByteArray()
的作用相同,只是其返回值的元素是不可变的

从for
ByteArray()

如果[first parameter]是整数,则数组将具有该大小,并将使用空字节初始化

因此,当您在整数中调用
Byte(x)
where
x
时,总是会得到一个大小为
x
的零字节序列


\xhh
是python在字节文本中使用时表示具有十六进制值hh的字节<代码>b'\x00'前面有一个b,这意味着它是一个字节文字。

请为“\x”@NitinPawar info added”添加信息