Good Comments Explain Why
# Bad: explains what the code already says x = x + 1 # add 1 to x # Good: explains intent x = x + 1 # compensate for 0-based indexing
Docstrings for Functions
def grade(score):
"""Return letter grade for 0-100 score."""
...
When to Delete Comments
- The code changed and the comment is now wrong.
- The comment is just a direct translation of the code.
- A good variable name makes the comment redundant.
HKDSE Marking Note
Comments are not formally awarded marks, but markers see cleaner work when you explain non-obvious decisions โ and partial credit is easier to award when intent is clear.
Practise this on PyForm โ free
PyForm runs Python in your browser with an AI tutor trained for HKDSE. No install, no credit card.
Open PyForm โ