gpt4 book ai didi

Python 3.5 当字符串中有 Enter 时换行

转载 作者:太空宇宙 更新时间:2023-11-03 15:43:55 26 4
gpt4 key购买 nike

当我输入包含换行符的字符串输入时,Python 认为我已按 Enter 键并继续执行下一个命令。

当按下 Enter 键时,如何输入 \n,将其余部分发送到额外的行?

最佳答案

在Python中,如果你有一个段落要不间断地执行,使用三引号。这是一个示例:

para_str = """this is a long string that is made up of
several lines and non-printable characters such as
TAB ( \t ) and they will show up that way when displayed.
NEWLINEs within the string, whether explicitly given like
this within the brackets [ \n ], or just a NEWLINE within
the variable assignment will also show up.
"""
print (para_str)

关于Python 3.5 当字符串中有 Enter 时换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41920673/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com