Comments in Python

It is very convenient to be able to write notes and tips to other developers (or yourself) and include those alongside your code.

There are two types of comments in Python, shown below.

Single-Line Comment

The hash # character can be used to leave a comment:

# this is a comment
favorite_fruit = "apple"    # another comment

Everything after the # (on the same line) is ignored by Python.

Multi-Line Comment

Three double-quote characters put together """ can be used to create a comment that spans multiple lines:

"""This is also a comment
   and it can span multiple
   lines
"""
favorite_fruit = "peach"

Comments

Leave a comment

What color are brown eyes? (spam prevention)
Submit
Code under MIT License unless otherwise indicated.
© 2020, Downranked, LLC.