如何做多行注释?大多数语言都有块注释符号,比如:
/*
*/
如何做多行注释?大多数语言都有块注释符号,比如:
/*
*/
当前回答
Python 2.7.13:
单:
"A sample single line comment "
多行:
"""
A sample
multiline comment
on PyCharm
"""
其他回答
要注释掉Python中的多行代码,只需在每一行上使用# single-line注释:
# This is comment 1
# This is comment 2
# This is comment 3
要在Python中编写“正确的”多行注释,就是使用带有“”语法的多行字符串 Python有文档字符串(或文档字符串)特性。它为程序员提供了一种简单的方法,可以为每个Python模块、函数、类和方法添加快速注释。
'''
This is
multiline
comment
'''
另外,提到您可以通过这样的类对象访问docstring
myobj.__doc__
在Python 2.7中,多行注释是:
"""
This is a
multilline comment
"""
如果你在一个类中,你应该正确地制表。
例如:
class weather2():
"""
def getStatus_code(self, url):
world.url = url
result = requests.get(url)
return result.status_code
"""
多行注释实际上在Python中并不存在。下面的示例包含一个未赋值的字符串,Python将验证该字符串是否存在语法错误。
一些文本编辑器,如notepad++,为我们提供了注释掉一段书面代码或单词的快捷方式。
def foo():
"This is a doc string."
# A single line comment
"""
This
is a multiline
comment/String
"""
"""
print "This is a sample foo function"
print "This function has no arguments"
"""
return True
此外,Ctrl + K是notepad++中阻止注释的快捷键。它在选定的每一行前面添加一个#。Ctrl + Shift + K表示取消注释。
是的,你可以简单地使用
'''
Multiline!
(?)
'''
or
"""
Hello
World!
"""
好处:它有点难,但在旧版本、打印函数或gui中使用更安全:
# This is also
# a multiline comment.
对于这个,你可以选择你想要注释的文本,并按Ctrl /(或⌘/),在PyCharm和VS Code中。
但是你可以编辑它们。例如,可以更改快捷键“Ctrl /” 按Ctrl Shift C。
警告!
小心,不要覆盖其他快捷方式! 注释必须正确缩进!
希望这个回答能有所帮助。祝你下次写出其他答案时好运!
Python 2.7.13:
单:
"A sample single line comment "
多行:
"""
A sample
multiline comment
on PyCharm
"""