相关疑难解决方法(0)

为什么Python没有多行注释?

好的,我知道三引号字符串可以作为多行注释.例如,

"""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风格指南,但我无法找到技术答案,为什么没有正式实现多行,/**/类型的评论.我使用三引号没有问题,但我对导致这个设计决定的原因有点好奇.

python comments multiline

243
推荐指数
8
解决办法
15万
查看次数

Python Programming: Multiline Comments before an Else statement

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)

python comments if-statement

4
推荐指数
1
解决办法
1826
查看次数

标签 统计

comments ×2

python ×2

if-statement ×1

multiline ×1