Comments explain your code and are ignored by Python.
A comment starts with # and runs to the end of the line.
For multi-line notes, use several # lines, or a triple-quoted string """...""".
A triple-quoted string right after a function definition is a docstring: the function's documentation.
💡 Key Takeaways: Python Comments
Mastering Python Comments helps you write clean and reliable Python code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
Python Comments Code Example
Python
# This is a comment
print("Hello") # comment at the end of a line
"""
This text is not assigned to anything,
so Python ignores it.
"""
def area(r):
"""Return the area of a circle with radius r."""
return 3.14159 * r * r
print(area(2))
print(area.__doc__)
Free sign-in required · Google login available
Python Comments Practice Exercises
Check what you learned in “Python Comments”.
/ 3 solved
Fill in the blank
Write a comment.
This is a comment
✓ Correct!Not quite. Try again.
Multiple choice
What is a docstring?
✓ Correct!Not quite. Try again.
Code challenge
Comment out the second line so only "Keep" is printed.
Write the code in the live editor. Your answer is checked automatically.