PCEP-30-02 practice question 19 of 35
How can you create multiline comments in Python? (select 3)
Full set: 548 questionsDomain Computer Programming and Python Fundamentals
Python does not have a specific syntax for multiline comments in the way other languages might use / ... /. However, the effect of a multiline comment can be achieved in two ways. The most direct method is to create a block of single-line comments by starting each line with a hash (#) symbol. Alternatively, Python's syntax for multiline string literals, which uses either triple double-quotes ("""...""") or triple single-quotes ('''...'''), can be used. When a multiline string is not assigned to a variable or used in an expression, the Python interpreter ignores it during execution, making it function as a de facto multiline comment. This technique is also the standard for creating documentation strings (docstrings).
A. The and syntax is not a valid comment format in Python.
C. The / and / syntax is used for block comments in languages like C, Java, and JavaScript, but not in Python.
F. The -- and -- syntax is used for comments in languages like SQL and Ada, but it is not valid in Python.
1. Python Institute, Python Essentials 1, Module 2, Section 2.1.5 – Comments: "If you want to add a comment that spans several lines, you need to put a hash at the beginning of each line." This directly supports option D.
2. Official Python 3 Documentation, The Python Tutorial, Section 3.1.2. Strings: "String literals can span multiple lines. One way is using triple-quotes: """...""" or '''...'''... Often used for docstrings". This supports the use of triple-quoted strings (options B and E) which, when not assigned, act as comments.
3. Severance, C. R. (2016). Python for Everybody: Exploring Data in Python 3. Chapter 2, Section 2.8 - Comments, Page 23: "As your programs become bigger and more complicated, they get more difficult to read... It is a good idea to add notes to your programs to explain in natural language what the program is doing. These notes are called comments, and they start with the # symbol... Anything from the # to the end of the line is ignored". This reference supports option D as the primary method for commenting. The book later introduces multiline strings for docstrings.
Keep practicing
Take the free PCEP-30-02 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other PCEP-30-02 practice questions
- Question 1The following list is given:
- Question 2What is the output of the following code? num = 10 while num >= 0: num -= 2 print(num)
- Question 4We need to check if at least one element of the iterable object evaluates to the truth. W…
- Question 5This question is a tricky one. What is the result of the following code snippet? numbers …
- Question 8What is the purpose of the continue statement in Python?
- Question 11We need to check if all elements of the iterable object evaluate to the truth. What built…
