如何在 Python 字典中添加注释?


你可以像往常一样在 Python 脚本中的任何地方添加注释。但请注意,你只能使用 # 添加单行注释。多行注释就像字符串,在字典定义之间不能只放一个字符串。例如,以下声明是完全有效的

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

但以下声明是不行的

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

更新于: 2020 年 6 月 17 日

415 个浏览量

开启你的事业

完成课程获得认证

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