Do I always need to include comments?


#1

Question

Do I need to write comments for any code that I write, or is there some standard I should follow?

Answer

It’s a good idea to write comments for anything that is potentially ambiguous. If possible, avoid ambiguous variable/function/class names. But if it can’t be helped, comments can clear up confusion.
Another good reason to write comments is to explain functionality. A very common practice is writing documentation (via comments) for each function in your program. You’ll typically see a description of what it does and how to use it, as a minimum.

Comments will end up making your code easier to maintain because it’ll help you, and other programmers who read it, remember what was going on when you wrote it six months ago!


FAQ: Learn Python - Python Syntax - Comments