我已经读过这个:Why doesn't Python have multiline comments?
所以在我的 IDLE 中,我写了一条评论:
Hello#World
world 之后的任何内容也是评论的一部分。在 c++ 中,我知道一种关闭评论的方法,例如:
/*Mycomment*/
有没有办法在 Python 中结束评论?
注意:我不想不使用三重引号。
请您参考如下方法:
您已经阅读过没有多行注释,只有单行注释。注释导致 Python 忽略行尾之前的所有内容。你用换行符“关闭”它们!
我不是特别喜欢它,但有些人使用多行 strings 作为注释。由于您只是丢弃了该值,因此您可以通过这种方式近似评论。它真正做任何事情的唯一时间是当它位于函数或类 block 的第一行时,在这种情况下,它被视为 docstring。 .
另外,这可能更像是一个 shell 脚本约定,但是使用多个单行注释有什么不好呢?
#####################################################################
# It is perfectly fine and natural to write "multi-line" comments #
# using multiple single line comments. Some people even draw boxes #
# with them! #
#####################################################################
