Python Comments
📝 Python Comments
Python Comments are non-executable statements used to explain code. They are ignored by the Python interpreter and do not affect program output.
Comments are helpful for:
✔ Explaining logic
✔ Documenting code
✔ Making code readable
✔ Debugging
✅ 1. Single-Line Comment
Single-line comments begin with the # symbol.
Example:
✅ 2. Inline Comment
A comment written on the same line as code.
✅ 3. Multi-Line Comment
Python doesn’t have a specific multi-line comment syntax, but we use triple quotes " """ or ' '''' for documentation.
Example:
Another example:
🧩 Use Case: Documenting Functions (Docstrings)
Triple quotes are also used for docstrings — documentation for functions, classes, and modules.
Example:
🎯 Python Comments Best Practices
✔ Write meaningful comments
✔ Don’t over-comment simple code
✔ Use comments to explain why, not just what
❌ Bad:
✔ Good:
▶ Example Program with Comments
Summary Table
| Type | Symbol | Example |
|---|---|---|
| Single-line comment | # |
# Comment here |
| Inline comment | # |
x = 10 # Explanation |
| Multi-line comment | ''' ''' or """ """ |
"""This is multi-line comment""" |
| Docstring | """ """ |
Function description |
