Comments document code for others to understand from "summary" of Python Programming by John M. Zelle
When writing code, it is crucial to remember that it is not just for the eyes of the person who wrote it. Others will invariably have to read and work with your code at some point. This is where comments come into play. Comments are lines of text in your code that are meant to be human-readable explanations of what the code is doing. They are not executed by the computer; rather, they are there to help people understand the code. Comments can take many forms, from simple explanations of what a particular block of code is doing to more detailed descriptions of the overall purpose of a program. They can also be used to temporarily disable certain lines of code for testing purposes. In essence, comments are your way of communicating with other programmers who might need to understand or modify your code in the future. When writing comments, it is important to be clear and concise. Avoid unnecessary jargon or overly technical language that might confuse someone unfamiliar with the code. Instead, focus on explaining the logic behind your code in a way that is easy to follow for someone with a basic understanding of programming. It is also a good idea to include comments throughout your code, rather than just at the beginning or end. This makes it easier for someone to quickly grasp what each section of code is doing without having to decipher it line by line. In addition to helping others understand your code, comments can also be a valuable tool for yourself. When you come back to a project after some time away, having well-documented comments can jog your memory and make it easier to pick up where you left off.- Comments are an essential part of writing clean, maintainable code. By taking the time to document your code thoroughly, you can make life easier for both yourself and anyone else who might need to work with your code in the future.