A note on the fridge
"Save the cake for Sunday!" The fridge ignores it. It is for your family.
11CLEAN CODE · COMMENTS
A line that starts with # is a comment: a note for people that Python skips.
IN REAL LIFE
People leave short notes so others know the plan or the reason.
"Save the cake for Sunday!" The fridge ignores it. It is for your family.
"Stir slowly so it won't burn." It tells you why, not only what.
Your teacher writes "Test on Friday!" in the margin. The book stays the same.
LOOK FIRST
Python skips everything after # on that line. It is only for people.
# add 1 is obvious. # bonus for finishing first explains the reason.
When you change the code, change the comment too. Python never checks it.
LOOK FIRST
Lines with # are for people. The others are for Python.
# Plan: count the cookies for the partyThe plan, for people. Python skips it.cookies = 12Python runs this: a box with 12.# Mia brings 6 more for her friendsExplains WHY the next line adds 6.cookies = cookies + 6Now the box keeps 18.# print("Not yet!")A line switched off with #. Python skips it.print("Cookies:", cookies)A blank line before it groups the steps: count first, then show.RUN IT
Guess first. Then run real Python and check.
# Plan: count the cookies for the party
cookies = 12
# Mia brings 6 more for her friends
cookies = cookies + 6
# print("Not yet!")
print("Cookies:", cookies)What will Python show?
PyBot's hint
Ready. Press Run Python.
Pyodide 314.0.3 runs CPython in your browser with WebAssembly.
Open-source under the Mozilla Public License 2.0. License
Now change one thing: Delete the # before print("Not yet!") and run again.
YOUR TURN
Try each tiny question. A wrong answer becomes something to review.
Which note on a cake box helps most?
# print("Hello")
print("Bye")What will Python show?
lives = 3Which comment helps most above this line?
# PyBot has 5 stickers
stickers = 8
print(stickers)What will Python show?
print("Start")
print("Beep beep beep!")
print("End")How do you skip line 2 for a test, without deleting it?
# score = 10
score = 5 # starting score
#print(score)Which line does Python really run?
What does the blank line do?
Tickets now cost 3 coins, but an old comment still says 2, and line 5 trusted it. Fix the code and the comment.
Total: 12 coinsOUTPUT
Want a fresh start? Clear only this page.
Python skips everything after #. Explain why, keep notes true, and use blank lines to group steps.