# How to put multi-line comments inside a Python dict()?

PythonProgramming

You can put comments like you normally would anywhere in a python script. But note that you can only put single line comments using #. Multiline comments act like strings and you cannot put just a string in between definition of a dict. For example, the following declaration is perfectly valid −

## Example

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

But the following is not −

testItems = {
'TestOne': 'Hello',
"""
Some random
multiline comment
"""
}
Published on 19-Apr-2018 14:21:36