我偶尔使用Python几个月,我知道我们可以使用#和""或""来评论.但是当我想评论一些字典的项目时,用评论词('''),我失败了.
testItems = {
'TestOne':
{
"NameId":101
"Score":99
},
'''
'TestTwo':
{
"NameId":101
"Score":99
}
'''
}
Run Code Online (Sandbox Code Playgroud)
然后我得到SyntaxError: invalid syntax指向最后'''位置的错误.
我也知道python语言有一些缩进规则.但我尝试了这么多缩进的可能性,仍然失败了.
您只能在允许使用字符串的地方使用'''或"""来注释,因为它们不会创建注释,而只是创建字符串。
在您描述的情况下,不允许您放置字符串。要么将结束语}向上移动,要么逐行取消注释不需要的代码部分。
正在做
test_items_1 = {
"NameId":101,
"Score":99
}
test_items_2 = {
"NameId":101,
"Score":99
}
testItems = {
'TestOne': test_items_1,
# 'TestTwo': test_items_2,
}
Run Code Online (Sandbox Code Playgroud)
也可以。