Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嘿,我想在 Python 中声明一个字符串,它是一个长文本(带有换行符和段落)。这可能吗?如果我只是将文本复制粘贴到引号中,Python 只能识别第一行,如果我想要整个文本,我必须手动删除所有换行符。如果这是可能的,如果文本有引号(“”)仍然可能吗?
使用三引号:
mytext = """Some text Some more text etc... """
用 """ 将字符串内容括起来以表示多行字符串。
>>>a = """ ...this ...is ...a ...multi-line ...string ...""" >>> a 'this\nis\na\nmulti-line\nstring\n'