snippetpythonCritical
How do I create multiline comments in Python?
Viewed 0 times
howpythoncommentsmultilinecreate
Problem
How do I make multi-line comments? Most languages have block comment symbols like:
/*
*/Solution
You can use triple-quoted strings. When they're not a docstring (the first thing in a class/function/module), they are ignored.
(Make sure to indent the leading
Guido van Rossum (creator of Python) tweeted this as a "pro tip".
However, Python's style guide, PEP8, favors using consecutive single-line comments, like this:
...and this is also what you'll find in many projects. Text editors usually have a shortcut to do this easily.
'''
This is a multiline
comment.
'''(Make sure to indent the leading
''' appropriately to avoid an IndentationError.)Guido van Rossum (creator of Python) tweeted this as a "pro tip".
However, Python's style guide, PEP8, favors using consecutive single-line comments, like this:
# This is a multiline
# comment....and this is also what you'll find in many projects. Text editors usually have a shortcut to do this easily.
Code Snippets
'''
This is a multiline
comment.
'''# This is a multiline
# comment.Context
Stack Overflow Q#7696924, score: 2226
Revisions (0)
No revisions yet.