coding180 icon
Coding180
6 - Python comments

6 - Python comments

Home > Tutorials > Python for beginners > Getting started with Python


In Python, Comments are a way to add notes to your code that the computer will ignore. These notes can help you remember what the code does, or explain it to someone else.

In Python, comments are denoted using the "#" symbol. Any text following the "#" symbol on a line is considered a comment and is ignored by the interpreter.

For example, you can use comments to explain what a certain line of code does, like this:

#This line of code calculates the average of three numbers
avg = (num1 + num2 + num3) / 3

In this example, the comment on the first line provides additional information about the code that follows it. The comment is ignored by the computer, but it can be helpful for someone reading the code to understand its purpose.

You can also use comments to temporarily disable parts of your code, like this:

#This line of code is not ready yet, so I am commenting it out
print(my_favorite_color)

In this example, the comment symbol is used to comment out the print statement on the second line. This means that the computer will ignore that line of code, and it will not be executed. This can be helpful if you want to test or modify the code later.

Overall, comments are a useful tool in Python that can help you add explanations and notes to your code, and to temporarily disable parts of your code as needed.


user

Robort Gabriel

Lagos, Nigeria

Freelance Web Developer, Native Android Developer, and Coding Tutor.

Skills
  • UI / UX
  • JavaScript
  • Python
  • PHP
  • Kotlin
  • Java
  • Bootrap
  • Android
  • Laravel