Skip to main content
 首页 » 编程设计

javascript之Python 中 Javascript 中三引号字符串的替代方案

2025年05月04日19lautakyan007

<分区>

Python 有提供自由文本输入的三引号字符串。不需要下一行字符来定义下一行。这是一个例子;

 hello = """ 
 
            This string is bounded by triple double quotes (3 times "). 
        Unescaped newlines in the string are retained, though \ 
        it is still possible\nto use all normal escape sequences. 
 
            Whitespace at the beginning of a line is 
        significant.  If you need to include three opening quotes 
        you have to escape at least one of them, e.g. \""". 
 
            This string ends in a newline. 
        """ 

所以我有一个由段落组成的 HTML 文本。我可以在段落之间添加空格,但我认为如果 javascript 具有像 Python 的三重引号字符串这样的功能,我可以用它生成段落。

在 Javascript 中是否有像 Python 那样的替代自由文本用法,或者您可以建议一个正在执行此操作的 Javascript 库吗?

谢谢!