在Python中,换行符通常使用 `\n` 表示。当你在字符串中使用 `\n` 时,它会被解释为换行符,并在打印输出时在该位置进行换行。例如:
print("Hello,\nWorld!")
输出结果为:
Hello,
World!
如果你想在 `print` 函数中输出包含换行符的文本,你可以使用多个参数,每个参数代表一行文本。例如:
print("Python is\nawesome")
输出结果为:
Python is
awesome
请注意,在字符串中,如果 `\n` 后面有空格,它仍然会被解释为换行符的一部分,除非你使用 `\\n` 来表示字面上的反斜杠和 `n` 字符。例如:
print("This is a line with a newline character: \\n")
输出结果为:
This is a line with a newline character: \n