在 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

更新於: 2020-06-17

761 次瀏覽

開啟您的 職業生涯

完成課程後獲得認證

開始
廣告
© . All rights reserved.