Tutorial
Python Comments
In Python, comments are used to leave notes or explanations in your code. They are ignored by Python when your program runs.
Why Use Comments?
- Explain what your code does so others can understand it.
- Help yourself remember why you wrote certain code.
- Python ignores comments when running your program.
Single-line Comments
A single-line comment starts with the # symbol. Anything after # on that line is a comment.
Example
When you run the code above, Python will only execute the print() line. The comments are ignored.
Multi-line Comments
For longer comments spanning multiple lines, you can use triple quotes """ """.
Example
Python ignores everything inside the triple quotes if it's not assigned to a variable. Only the print() line will run.