好的,我知道三引号字符串可以作为多行注释.例如,
"""Hello, I am a
multiline comment"""
Run Code Online (Sandbox Code Playgroud)
和
'''Hello, I am a
multiline comment'''
Run Code Online (Sandbox Code Playgroud)
但从技术上讲这些都是字符串,对吗?
我用谷歌搜索并阅读了Python风格指南,但我无法找到技术答案,为什么没有正式实现多行,/**/类型的评论.我使用三引号没有问题,但我对导致这个设计决定的原因有点好奇.
I was working with simple if-else statements in Python when a syntax error came up with the following code.
"""
A multi-line comment in Python
"""
if a==b:
print "Hello World!"
"""
Another multi-line comment in Python
"""
else:
print "Good Morning!"
Run Code Online (Sandbox Code Playgroud)
This code gives a syntax error at the "else" keyword.
The following code however does not:
"""
A multi-line comment in Python
"""
if a==b:
print "Hello World!"
#One single line comment
#Another single line comment
else:
print …Run Code Online (Sandbox Code Playgroud)