How to Create Multiline Comments in Python
Created
Modified
Using triple-quoted Strings
String literals can span multiple lines. One way is using triple-quotes: """...""" or '''...'''.
You can use triple-quoted strings. When they're not a docstring, they are ignored.
See the following example:
#!/usr/bin/python3
'''
This is a multiline
comment.
'''
""""
This is a multiline
comment.
"""
def parses(token):
"""
This function parses a token.
TODO: write a decent docstring :-)
"""
pass
Make sure to indent the leading ''' appropriately to avoid an IndentationError.
Using Consecutive Single-Line Comments
Python's style guide, PEP8, favors using consecutive single-line comments, like this:
#!/usr/bin/python3
# This is a multiline
# comment.
Python Errors
IndentationError: unexpected indent
#!/usr/bin/python3
'''...
''' IndentationError: unexpected indent