Skip to main content

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

Use descriptive variable names instead of comments when possible. days_in_week = 7 is clearer than d = 7 # days.

Temporary comments

Use comments to disable code temporarily:

Common mistakes

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