什么是“”“......”“”“”在一个功能吗? [英] What does the """...""" in a function do?
本文介绍了什么是“”“......”“”“”在一个功能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这三个在函数中是什么意思(在python中),其中包含一条消息?
我们不能用#来表示这样的报告吗?这是我的一个例子:
What do the three " mean in a function (in python) with a message in it?
Can't we use a # for such a report? Here is an example of what I n:
def make_sandwich(*items):
"""Make a sandwich with the given items."""
print("\nI'll make you a great sandwich:")
for item in items:
print(" ...adding " + item + " to your sandwich.")
print("Your sandwich is ready!")
所以我的意思是de def下的第一句话(给定项目做一个sandwish 。
谢谢
我尝试过:
试图在谷歌上找到它但没有成功
So what i mean is the first sentence under de def ("""Make a sandwish with the given items.""")
Thank you
What I have tried:
Tried to find it on google but no sucess
推荐答案
这个问题包括2问题,一个关于数据类型,另一个关于该放置的目的。
首先,如解决方案1的答案,这是一个字符串定义。在Python中,你不是克制ned使用单引号创建一个字符串,你可以使用多种方式,这个三重双引号就是其中之一。
就放置而言,该放置使该字符串成为该函数的注释。因此,任何试图使用该功能的人都可以将其视为帮助者评论。为此,请参见评论的正确方法是什么python中的函数? - 堆栈溢出 [ ^ ]
That is a question that includes 2 questions, one about the data type, and second the purpose of that placement.
First of, as Solution 1 answers, that is a string definition. In Python, you are not restrained to use a single quote to create a string, you can use multiple ways and this triple double quote is one of them.
And as far as the placement is concerned, that placement makes this string a comment for the function. Thus, anyone trying to use the function will be able to see this as a helper comment. For that, see here What is the proper way to comment functions in python? - Stack Overflow[^]
你的google-fu需要一些工作 - 一个微不足道的谷歌找到的负载: python三个双引号 - Google搜索 [ ^ ]
直接到这里: Python字符串 | Python教育 | Google Developers [ ^ ]
Your google-fu needs some work - a trivial google found loads: python three double quotes - Google Search[^]
And straight to here: Python Strings | Python Education | Google Developers[^]
谢谢你们,我是编程的新手:)但我想你注意到了哈哈
Thank you guys, i'm new to programming:) But i think you noticed that haha
这篇关于什么是“”“......”“”“”在一个功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文