I have used Python occasionally for several months, I know we can use # and """ or ''' to comment. But when i wanted to comment some items of a dictionary, with comment words ('''), i failed.
testItems = {
'TestOne':
{
"NameId":101
"Score":99
},
'''
'TestTwo':
{
"NameId":101
"Score":99
}
'''
}
then i get ther error of SyntaxError: invalid syntax
pointing to the last ''' position.
I also know there are some indent rule of python language. But i tried so many indent possibility, still fail.
You can only use '''
or """
to comment where strings are allowed as these don't create comments, but just strings.
In the situation you describe, you are not allowed to put a string. Either move the closing }
upwards or uncomment your unwanted code part line by line.
Doing
test_items_1 = {
"NameId":101,
"Score":99
}
test_items_2 = {
"NameId":101,
"Score":99
}
testItems = {
'TestOne': test_items_1,
# 'TestTwo': test_items_2,
}
would work as well.
Values in between '''
or """
within dictionary will be considered as another item, not comment.
In your case the the content between '''
is treated as another item's key in that dictionary.
You have to use #
to comment the unwanted codes.
Ex:
testItems = {
'TestOne':
{
"NameId":101,
"Score":99
},
# 'TestTwo':
# {
# "NameId":101
# "Score":99
# }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With