Follow the transformation
Use # for concise notes about intent, assumptions or non-obvious constraints.
Prefer descriptive names so the code explains what a value represents.
Keep comments synchronised with the code when behaviour changes.
Comments explain intent that is not obvious from the code itself.
Comments explain intent that is not obvious from the code itself. In Python, a line comment begins with # and is ignored by the interpreter. Readability also comes from meaningful names, small functions, consistent layout and code that expresses one idea at a time; comments should clarify why a choice exists rather than narrate every obvious operation.
Learning goal: explain why Comments and Readable Code behaves this way, apply it to a small example, and verify the result independently. Begin by being able to justify this first step: Use # for concise notes about intent, assumptions or non-obvious constraints.
Treat this as a sequence of observable decisions rather than one opaque command. Stage 1: Use # for concise notes about intent, assumptions or non-obvious constraints. Stage 2: Prefer descriptive names so the code explains what a value represents. Stage 3: Keep comments synchronised with the code when behaviour changes. Final checkpoint: Remove commented-out obsolete code from finished work; version control is a better archive.
Use # for concise notes about intent, assumptions or non-obvious constraints.
Prefer descriptive names so the code explains what a value represents.
Keep comments synchronised with the code when behaviour changes.
# Revenue excludes refunded orders.
# Step 1 — Compute the right-hand expression and store its result in `net_revenue` for the next step.
net_revenue = gross_revenue - refunds
# Step 2 — Display the current value explicitly so the result/state can be inspected during execution.
print(net_revenue)The comment records a business rule; the variable name records what the computed value represents.
For Comments and Readable Code, trace the specific input through the mechanism above and independently verify one returned value, state change or side effect.
InputObjects/values supplied to the operation.StateNames or mutable objects that may change during execution.OutputReturned value, side effect, file, plot or exception to inspect.Use Comments and Readable Code when it answers a defined question in Getting Started with Python and its inputs/assumptions match the current data or program state.
Reconsider Comments and Readable Code when the required information is unavailable, the operation would violate a validation/data boundary, or a simpler operation answers the question more transparently.
Construct a tiny example of Comments and Readable Code. First use # for concise notes about intent, assumptions or non-obvious constraints. Then prefer descriptive names so the code explains what a value represents. Predict the result before execution and explain one boundary or failure case.
Which approach best demonstrates understanding of Comments and Readable Code?
Step 1Use # for concise notes about intent, assumptions or non-obvious constraints.Step 2Prefer descriptive names so the code explains what a value represents.Step 3Keep comments synchronised with the code when behaviour changes.Step 4Use docstrings for public module/function/class documentation rather than long comment blocks.