Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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?
print('Hello') # This prints Hello
The output will be:
Hello
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<!--
✗ Incorrect
In Python, the # symbol starts a comment. Other symbols are used in different languages.
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
✗ Incorrect
Comments are ignored by Python and do not affect the program.
How can you write a multi-line comment in Python?
AUse multiple lines starting with #
BUse /* and */
CUse <!-- and -->
DUse // on each line
✗ Incorrect
Python uses multiple single-line comments starting with # for multi-line comments.
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
✗ Incorrect
Comments do not affect speed; they only help with understanding.
What will this code print? print('Hi') # This is a greeting
AHi # This is a greeting
BError
CThis is a greeting
DHi
✗ Incorrect
The comment after # is ignored, so only 'Hi' is printed.
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.
Practice
(1/5)
1. What symbol is used to write a single-line comment in Python?
easy
A. /* */
B. //
C. #
D.
Solution
Step 1: Identify the comment symbol in Python
Python uses the # symbol to start a single-line comment.
Step 2: Compare with other languages
Other symbols like // or /* */ are used in languages like JavaScript or C, not Python.
Final Answer:
# -> Option C
Quick Check:
Single-line comment = # [OK]
Hint: Single-line comments start with # in Python [OK]
Common Mistakes:
Using // instead of #
Using /* */ for single-line comments
Confusing HTML comments with Python
2. Which of the following is the correct way to write a multi-line comment in Python?
easy
A.
B. '''This is a multi-line comment'''
C. // This is a multi-line comment //
D. /* This is a multi-line comment */
Solution
Step 1: Recognize Python multi-line comment style
Python uses triple single quotes ''' or triple double quotes """ for multi-line comments or docstrings.
Step 2: Eliminate other language comment styles
Options A, B, and D are comment styles from other languages like HTML, JavaScript/C++, and C.
Final Answer:
'''This is a multi-line comment''' -> Option B
Quick Check:
Multi-line comment = triple quotes [OK]
Hint: Use triple quotes ''' or """ for multi-line comments [OK]
Common Mistakes:
Using // or /* */ which are not Python syntax
Using HTML style comments
Trying to use # for multi-line comments without repeating
3. What will be the output of the following code?
print('Hello') # This prints Hello
# print('World')
medium
A. Hello
B. SyntaxError
C. World
D. Hello\nWorld
Solution
Step 1: Understand the effect of comments on code execution
The first line prints 'Hello' because the comment after it does not affect the print statement.
Step 2: Recognize that the second print is commented out
The second print statement is fully commented out, so it does not run or print anything.
Final Answer:
Hello -> Option A
Quick Check:
Commented code does not run = Hello [OK]
Hint: Code after # is ignored; only uncommented lines run [OK]
Common Mistakes:
Thinking commented print runs
Expecting both Hello and World printed
Confusing comment with string
4. Find the error in this code snippet:
# This is a comment
print('Start')
'''This is a comment without an end
print('End')
medium
A. Comments cannot be placed before print statements
B. No error, code runs fine
C. print('End') is outside comment and runs normally
D. Missing closing triple quotes causes SyntaxError
Solution
Step 1: Check triple quote usage
The triple quotes start a multi-line comment but are not closed, causing a syntax error.
Step 2: Understand impact on code parsing
Without closing quotes, Python treats the rest as part of the string, leading to a SyntaxError.
Final Answer:
Missing closing triple quotes causes SyntaxError -> Option D
Quick Check:
Unclosed triple quotes = SyntaxError [OK]
Hint: Always close triple quotes to avoid syntax errors [OK]
Common Mistakes:
Ignoring missing triple quote closure
Thinking comments can be unclosed
Assuming code after triple quotes runs
5. You want to temporarily disable a block of code without deleting it. Which is the best way to do this in Python?
hard
A. Put # at the start of each line in the block
B. Surround the code block with triple quotes ''' ... '''
C. Use /* ... */ around the block
D. Wrap the block in
Solution
Step 1: Understand Python comment styles for disabling code
Python does not officially support block comments; the common way is to put # at the start of each line.
Step 2: Evaluate triple quotes usage
Triple quotes create a string literal, which may not disable code properly and can cause unexpected behavior if used improperly.
Step 3: Recognize other language comment styles
Options C and D are not valid in Python.
Final Answer:
Put # at the start of each line in the block -> Option A
Quick Check:
Disable code block = # per line [OK]
Hint: Use # on each line to disable code safely [OK]