Revise Computingrevisecomputing.co.uk
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates
At a glanceFeaturesStudentsPricingHow it worksFree GCSE notesExam dates

Knowledge organisers / Maintainable Code

Comments

All topicsPractise exam questions
Knowledge organiser

Maintainable Code

301.7c

Explain code blocks.

What you need to know

Comments are notes in the code that Python ignores. Use # for single-line comments. Good comments explain why code does something, not what it does (the code itself shows that).

Key points

  • # starts a single-line comment
  • Comments are ignored by Python
  • Explain WHY, not WHAT: # Apply 20% discount
  • Don't over-comment obvious code
  • Use comments to mark sections of a program

Code examples

Using comments
python
# Calculate final price with VAT
price = 50
vat = price * 0.2  # 20% VAT rate
total = price + vat
print(total)