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.
在 PHP 中,我可以这样做:
print <<<END This uses the "here document" syntax to output multiple lines END;
有没有办法在 Python 中做类似的事情?
我想转储一大块 HTML 而不必担心转义,例如尖括号。
Python 没有带有任意开始/结束标记的 heredocs。您可以使用三引号(单引号或双引号)来实现非常相似的效果:
print ''' This uses the "here document" syntax to output multiple lines '''
添加一个r以使其成为原始字符串,这样反斜杠也不会被特殊处理。r'''....'''
r
r'''....'''