Python(3.x): print(string , end='') 结果突出显示模符号 %

Python(3.x): print(string , end='') results in highlighted modulo symbol %

运行 下面的代码片段 (print_end.py)。除了以突出显示的模符号 %.

结尾外,输出符合预期

这个%怎么来的?我不知道在哪里可以找到文档参考。

如果再添加一行 print() 它将去掉 % 符号。

# txt = input('Give me anything: ')
txt = 'GitHub is NO.1!' 
print(f'print before loop: {txt}')
for s in txt:
    print(s, end='')
# print()

Pyenv 环境 Python 3.8.0 输出:

康达环境 Python 3.7.3 输出:

更多信息: macOS Catalina 10.15.1,zsh

我在这里报告@Leiaz 在 unix.stackexchange 上写的答案(供参考:Why ZSH ends a line with a highlighted percent symbol?):

出现这种情况是因为它是“部分线路”。默认情况下 zsh goes to the next line to avoid covering it with the prompt.

When a partial line is preserved, by default you will see an inverse+bold character at the end of the partial line: a "%" for a normal user or a "#" for root. If set, the shell parameter PROMPT_EOL_MARK can be used to customize how the end of partial lines are shown.

所以它不是 Python,这种行为与 ZSH 的配置方式有关。如果您 运行 在 bash 中使用相同的脚本,您将看到不同的行为。