python 将 \x00 连接为字符串

python concatenating \x00 as string

我正在尝试连接列表中的多个值,所有值都是字符串数据类型。

问题是每当我遇到 return 字符串 \x00 时,即使它存储为字符串“\x00”,代码也会停止执行并完成。

代码如下:

example = [5, "HELLO", "\x00", "abc", "\x00", 5]
print(example)

test = []
for value in example:
    test.append(str(value))
print("".join(test))

这是输出:

[5, 'HELLO', '\x00', 'abc', '\x00', 5]
5HELLO

如您所见,“HELLO”之后的所有内容是不是 included.Is 有办法解决这个问题吗?

对于我可能有的任何误解,我深表歉意,我仍在学习这门语言。

打印null characters in strings depends on the terminal/program being used, it might well be that your program/IDE stops printing a string when it encounters a null character, while other programs might print whitespaces or skip them. A similar question and answer can be found here: Printing Null Character ("\x00") in Python vs C