0
0
Pythonprogramming~5 mins

Comments in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What symbol is used to start a single-line comment in Python?
The # symbol is used to start a single-line comment in Python. Anything after # on that line is ignored by the Python interpreter.
Click to reveal answer
beginner
How do you write a multi-line comment in Python?
Python does not have a special multi-line comment syntax. Instead, you can use multiple single-line comments starting with # or use a multi-line string with triple quotes (''' or """) which is ignored if not assigned to a variable or used as a docstring.
Click to reveal answer
beginner
Why are comments important in Python code?
Comments help explain what the code does in simple words. They make the code easier to understand for others and for yourself when you come back later.
Click to reveal answer
beginner
Can comments affect how a Python program runs?
No, comments do not affect the program's behavior. The Python interpreter ignores comments completely when running the code.
Click to reveal answer
beginner
Example: What will this code output?<br>
print('Hello')  # This prints Hello
The output will be:<br>
Hello
<br>The comment after # is ignored and does not affect the output.
Click to reveal answer
Which symbol starts a comment in Python?
A/*
B//
C#
D<!--
What happens to comments when Python runs the code?
AThey are ignored
BThey are executed as code
CThey cause errors
DThey print on the screen
How can you write a multi-line comment in Python?
AUse multiple lines starting with #
BUse /* and */
CUse <!-- and -->
DUse // on each line
Which of these is NOT a reason to use comments?
AExplain code to others
BMake code run faster
CMake code easier to understand
DHelp yourself remember code purpose
What will this code print?<br>print('Hi') # This is a greeting
AHi # This is a greeting
BError
CThis is a greeting
DHi
Explain how to write comments in Python and why they are useful.
Think about how you would explain your code to a friend.
You got /4 concepts.
    Describe the difference between comments and code in Python.
    Focus on what Python does with comments versus code.
    You got /4 concepts.