How do you comment out code in Python using single-line comment?

Experience Level: Junior
Tags: Python

Answer

To comment a code out, type hash (#) character before the code you want to comment out. The text on a line that is after the hash (#) character is considered a comment and is not executed.

Example:

items = list[1, 2, 3] # This list has 3 items

# let's display the items
print(items)

Python for beginners
Python for beginners

Are you learning Python ? Try our test we designed to help you progress faster.

Test yourself