voidex/20-29 Areas/20 Programming/20.01 Python/comments.md

1.1 KiB

title tags aliases
Comments
python
syntax
comments
hash
commenting
commented-out code

[!note] What Are Comments? Comments are lines in your code that start with a #. Python completely ignores them during execution.

[!example] Example

# This will not run
print('This will run!')

[!info] Spacing and Readability

  • Blank lines are also ignored by Python.
  • Use blank lines and comments to group related code — just like paragraphs in writing.
  • Helps you (and others) read your code more easily later.

[!important] Best Practices

  • Use comments to explain why, not just what the code does.
  • Avoid redundant comments:
x = 5  # set x to 5    ❌ unnecessary
  • Use inline comments sparingly and only when clarity is needed.

[!info] Related Notes