Ziad Keekouri
last year
Ziadcountry asked

If Python ignores # comments, why do we use # at all?

Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi iad Keekouri,

Python ignores comments because comments are not for the computer, they are for people.

We use # comments to:

  • Explain what the code is doing, so it is easier to understand later.

  • Leave reminders for yourself, especially when you come back to the code after a few days.

  • Make code easier for others to read if you share it.

  • Temporarily disable a line without deleting it.

Example:

# This prints the first number
print(6)

# print(8)  # This line is disabled for now
print(88.3)

So even though Python does not run comments, they help you write cleaner code and avoid confusion.

If you have more questions, I am here to help 😊

Python
This question was asked as part of the Getting started with Python course.