擅长:python、mysql、java
<p>你所说的(我想)叫做<a href="http://docs.python.org/tutorial/controlflow.html#documentation-strings" rel="noreferrer">docstrings</a>(感谢Boud的链接)。</p>
<pre><code>def foo():
"""This function does absolutely nothing"""
</code></pre>
<p>现在,如果您从解释器中键入<code>help(foo)</code>,您将看到我在函数中输入的字符串。您还可以通过<code>foo.__doc__</code>访问该字符串</p>
<p>当然,字符串文字就是——文字字符串。</p>
<pre><code>a = "This is a string literal" #the string on the right side is a string literal, "a" is a string variable.
</code></pre>
<p>或者</p>
<pre><code>foo("I'm passing this string literal to a function")
</code></pre>
<p>它们可以通过多种方式定义:</p>
<pre><code>'single quotes'
"double quotes"
""" triple-double quotes """ #This can contain line breaks!
</code></pre>
<p>甚至</p>
<pre><code>#This can contain line breaks too! See?
''' triple-single
quotes '''
</code></pre>