如何在 Python dict() 中放置多行注释?


你在一个 Python 脚本任意位置都能像正常情况一样添加注释。但需要注意,只能使用 # 添加单行注释。多行注释的行为就如同字符串,并且你不能仅仅在 dict 的定义中放置一个字符串。例如,以下声明是完全有效的:

示例

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

但以下声明无效:

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

更新于:2020-03-05

273 次浏览

开启你的 职业生涯

通过学习课程获得认证

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