将注释放在 if...elif..else 结构中的何处?


你可以在 if...elif...else 语句中的任意位置放置注释,即在这些块中的每一个之前或在这些块中的每一个之内。请注意,虽然你不能将多行注释放在 elif 和 else 块之前,但作为这些注释实际上为隐含整个结构中断的字符串。例如,

# If check
if True:
   # Another Comment style
   print("If block")
# Else if statement
elif False:
   # Another Comment style
   print("elif block")
# Else
else:
   # Another Comment style
   print("Else block")

这将给出输出

If block

更新于: 17-6 月-2020

756 次浏览

开启你的职业生涯

完成课程获得认证

开始学习
广告
© . All rights reserved.