The Wayback Machine - https://web.archive.org/web/20250116094308/https://www.geeksforgeeks.org/python-comments/
Open In App

Python Comments

Last Updated : 01 Dec, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Comments in Python are the lines in the code that are ignored by the interpreter during the execution of the program.

  • Comments enhance the readability of the code.
  • Comment can be used to identify functionality or structure the code-base.
  • Comment can help understanding unusual or tricky scenarios handled by the code to prevent accidental removal or changes.
  • Comments can be used to prevent executing any specific part of your code, while making changes or testing.
python
# I am single line comment

""" Multi-line comment used
print("Python Comments") """

Comments in Python

In Python, single line comments starts with hashtag symbol #.

Python
# sample comment
name = "geeksforgeeks"
print(name)

Output
geeksforgeeks

Multi-Line Comments

Python does not provide the option for multiline comments. However, there are different ways through which we can write multiline comments.

Multiline comments using multiple hashtags (#)

We can multiple hashtags (#) to write multiline comments in Python. Each and every line will be considered as a single-line comment.

Python
# Python program to demonstrate
# multiline comments
print("Multiline comments")

Also Check: Interesting Fact about Python Multi-line Comments

Using String Literals as Comment

Python ignores the string literals that are not assigned to a variable. So, we can use these string literals as Python Comments

Python
'Single-line comments using string literals'

""" Python program to demonstrate
 multiline comments"""
print("Multiline comments")


Best Practice to Write Comments

These are some of the tips you can follow, to make your comments effective are:

  1. Comments should be short and precise.
  2. Use comments only when necessary, don’t clutter your code with comments.
  3. Avoid writing generic or basic comments.
  4. Write comments that are self explanatory.


Enhance your coding skills with DSA Python, a comprehensive course focused on Data Structures and Algorithms using Python. Over 90 days, you'll explore essential algorithms, learn how to solve complex problems, and sharpen your Python programming skills. This course is perfect for anyone looking to level up their coding abilities and get ready for top tech interviews.
Join the Three 90 Challenge and commit to completing 90% of the course in 90 days to earn a 90% refund. It’s the perfect way to stay focused, track your progress, and reap the rewards of your hard work. Take the challenge and become a DSA expert in Python today


Next Article
Practice Tags :

Similar Reads

three90RightbarBannerImg