In Python, there are several ways to add comments to your code. Here’s an example that demonstrates three different ways to add comments:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# This is a single-line comment """ This is a multiline comment """ ''' This is another multiline comment ''' print("This is some code.") # This is a comment on the same line as code |
In Python, single-line comments start with a #
symbol and continue until the end of the line. Multi-line comments can be added using either triple double quotes ("""
) or triple single quotes ('''
).
Note: It’s recommended to add comments to your code to help explain what your code does and make it easier for others (or yourself) to understand in the future.