What are comments?
Comments are notes for humans that Python ignores. They’re like sticky notes in your code that explain what’s happening. Why write comments?- Help others understand your code
- Help future you remember what you did
- Disable code temporarily
- Document complex logic
Single-line comments
Use# to start a comment:
Multi-line comments
For longer explanations, use triple quotes:Technically, triple quotes create a string that Python doesn’t use. Real multi-line comments don’t exist in Python, but this works the same way!
When to use comments
Good comments explain WHY, not WHAT:Best practices
Temporary comments
Use comments to disable code temporarily:Common mistakes
Outdated comments
Outdated comments
Over-commenting obvious code
Over-commenting obvious code
What’s next?
Now that you know the basics and how to document your code, let’s test your understanding with practice exercises!Practice & Exercises
Test and reinforce your understanding of Python basics