Let’s say we have a Python dict and we were to document the general format of the key-value pairs. For the lack of a better example, let’s take the following dict as an example:
The general format of the key-value pair is:
And to add this as comment, we might try this:
Let’s check the keys of this dict now.
Hold up! Why’d that modify the goku string? This is because surrounding something with """ doesn’t necessarily mean as comments in Python. It is just a multiline string. Imagine it as a string literal, which isn’t assigned to any variable. There’s no such thing as multiline comments in Python, unlike other programming languages. The right way to put multiline comments is by using #.
You’d recall using """ to put comments at the beginning of function/class, also otherwise known as docstrings. Well, what do you know, those docstrings aren’t really comments. It is just a string literal and a standard convention.
So the right way to put a comment in dict would be
There’s no such thing as multiline comment in Python. Use # at every line to truly create multiline comments.