如何在 Python 字典中添加註釋?


你可以像普通地在 Python 指令碼中隨處添加註釋一樣添加註釋。但請注意,你只能使用 # 新增單行註釋。多行註釋的行為像字串,而不能在字典定義中只放一個字串。例如,以下宣告是完全有效的

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

但是以下宣告不是有效的

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

更新於: 17-6-2020

415 次瀏覽

啟動您的 事業

完成本課程以取得認證

開始
廣告
© . All rights reserved.