Edu*_*scu 6 python comments no-op python-2.7
我经常需要临时注释一些代码,但是有些情况如下所述,注释单行代码会产生语法错误
if state == False:
print "Here I'm not good do stuff"
else:
# print "I am good here but stuff might be needed to implement"
Run Code Online (Sandbox Code Playgroud)
有什么东西可以作为NOOP来保持这种语法正确吗?
whi*_*ile 13
您正在寻找的操作是pass
.所以在你的例子中它看起来像这样:
if state == False:
print "Here I'm not good do stuff"
else:
pass
# print "I am good here but stuff might be needed to implement"
Run Code Online (Sandbox Code Playgroud)
你可以在这里阅读更多相关信息:http: //docs.python.org/py3k/reference/simple_stmts.html#pass
在Python 3中,它...
是一个非常好的pass
替代品:
class X:
...
def x():
...
if x:
...
Run Code Online (Sandbox Code Playgroud)
我将其视为"待完成",而pass
意味着"此页故意留空".
它实际上只是一个文字,很像None
,True
和False
,但他们优化了所有的相同.
归档时间: |
|
查看次数: |
7190 次 |
最近记录: |