1.1 KiB
1.1 KiB
title | tags | aliases | ||||||
---|---|---|---|---|---|---|---|---|
Comments |
|
|
[!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
- pythonSyntaxOverview — comments are part of Python's syntax rules
- variableNamingBestPractices — both promote writing readable, self-explanatory code
- conditionals — comments are often used to clarify branches or logic