--Originally published at Sierra's Blog
Comments in python are for you to explain humans what’s the function of the code you wrote.
Python can’t read those messages, it will simpy ignore them. It’s a very useful tool that everyone should use, because it could save a lot of time of your co-worker by not having to try to understand what the code does.
Ways to annotate a comment:
There are two ways to annotate a comment in Python and the only difference between them is the extension.
# – is used for a single line comment, commonly used to indicate what a part of the code does, to use it you just need to type #, it’s like saying: Hey python! ignore everything that comes after the #.
“”” – is used for a comment that needs more than one line, it works this way:
ADVICE:
Keep your messages updated, you don’t want a comment that contradicts what does the code say, it’s confusing and could make your co-worker waste time.
Never alter the case of identifiers.
Use inline comments only when necessary, don’t use comments if it’s obvious:
x = 2 # now x is worth 2.