Lesson 5 of 18 · 2 min
Comments — Notes That Python Ignores
The WHY — Why Write Comments?
Imagine reading code you wrote 3 months ago with no comments. You will stare at it and think "what was I doing here?" Comments are notes for humans — Python completely ignores them. They explain WHY your code does something (not just what it does).
Single-Line Comments — Use # Symbol
# This entire line is a comment — Python skips it completely # Use comments to explain what each part of your code does student_name = "Ahmed" # store the student's name in a variable age = 21 # store their age total = age + 4 # calculate what age they will be in 4 years print(total) # display the result to the screen
Output: 25
Multi-Line Comments — Use Triple Quotes
""" This is a multi-line comment. It can span as many lines as you want. Python stores it but does not execute it. Use this at the top of a file to explain what the whole program does. """ ''' You can also use single triple-quotes. Both styles work identically. Choose one style and stick with it. '''
Comments to Temporarily Disable Code
x = 10 # x is set to 10
# print("This is disabled") # put # at start to disable without deleting
print("This line runs") # this line runs normally
Output: This line runs
