如何在 Python dict() 中放置多行註釋?


你在一個 Python 指令碼任意位置都能像正常情況一樣添加註釋。但需要注意,只能使用 # 新增單行註釋。多行註釋的行為就如同字串,並且你不能僅僅在 dict 的定義中放置一個字串。例如,以下宣告是完全有效的:

示例

testItems = {
   'TestOne': 'Hello',
   # 'TestTwo': None,
}

但以下宣告無效:

testItems = {
   'TestOne': 'Hello',
   """
   Some random
   multiline comment
   """
}

更新於:2020-03-05

273 次瀏覽

開啟你的 職業生涯

透過學習課程獲得認證

開始學習
廣告
© . All rights reserved.