Python comments are
lines of code that are added to source code to provide explanatory information, not executed by the python interpreter. They are used to provide explanations, notes, or description within the code for developers/programmers to understand the code better. Python Comments are ignored during the execution of the program.
There are 2 types of Python comments
- Single line comment/one line comment
- Multiple line comment
Single line comment/one line comment
- Single Line comments begins with the hash character (#) and ends by the end of the line.
- Then Python is ignoring all text that comes after the # to the end of the line.
This is a Comment! >>> # print ("This is a Comment!") >>>
Multiple line comment
Multiple line comments use 3 single quotes before and after the part you want commented.
”’ print(“This is a Comment”) print(“This is also a Comment”) ”’ print(“This is not a Comment”) |
It’s important to note that python comments are not just for providing explanations to other developers; they can also be useful for temporarily disabling code during debugging or testing.
Good commenting practices help improve code readability and maintainability, making it easier for you and others to understand and work with your code in the future.