Commenting your code is always a good practice; It will be really helpful for other developers in understanding your code, as well as yourself, plus, it doesn’t affect the execution of the code at all. Depending on the purpose of your program, you can use comments as reminders, to-do list items, or you can add them as an explanation for other programmers to be able to understand what your code is doing.
In general, it is best to write comments while you are writing or updating a program as it is easy to forget your thought process later on, and comments written later may be less useful in the long term.
How To Add Comments to Python Code
Comments in Python start with dash (#) sign and followed by a space character:
# Hello, python! print( "Hey!" )
Block Comments in Python
Unlike many other languages, Python doesn’t have a block comment feature. So if you want to use multiple lines in a comment block, you have to start every line with a hash (#) character:
# Smile.py # This program prints smiley faces # Author: PythonDev.io Team print( 20 * ' :) ' )