2.4.8.1 字符串的语法

如何声明你想要的那个字符串

字符串的读取语法是一个双引号,加上任意数量的字符,再用一个双引号收尾。 " 比如这个 "( "like this")。如果想在字符串内包含双引号本号,那么你需要加上反斜杠进行转义。比如 "\"" 就是一个只包含一个双引号的字符串。类似的,如果你想再字符串内包含反斜杠,那你就得用另一个反斜杠去对反斜杠转义,比如:" this \\ is a single embedded backslash" 。

在字符串中会经常出现新行,不过这个新行符并不需要转义,直接换新行即可,Emcas 会自动处理。但是转义新行符,也就是在反斜杠 '\' 之后直接转新行,这种新行符会被忽略掉。同样,转义空格也会被忽略掉。

"It is useful to include newlines
in documentation strings,
but the newline is \
ignored if escaped."
     ⇒ "It is useful to include newlines
in documentation strings,
but the newline is ignored if escaped."

最后更新于