What is the correct method to comment multiple lines in Python?

Prepare for the WGU ITSW3170 D411 Scripting and Automation Exam. Utilize flashcards and multiple choice questions, each with hints and explanations, to enhance your study. Get exam-ready today!

In Python, the correct method to comment multiple lines is to use triple quotes, either """ or '''. This technique allows you to create a multi-line string that is not assigned to any variable, effectively serving as a block comment. When these triple quotes are placed around text, Python treats it as a string, but since it's not utilized in a way that impacts program flow, the text inside is ignored during execution. This is quite useful for documenting code or reminding yourself about certain functionalities without interrupting the code's execution.

Other methods mentioned, such as using "//" or "/* and */," are syntax from different programming languages like Java or C and are not applicable in Python for commenting purposes. Using "#" at the start of each line is valid for single-line comments but not efficient for extensive commentary across multiple lines. Thus, triple quotes provide a straightforward and readable approach for including lengthy notes or explanations in your code.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy