> ## Documentation Index
> Fetch the complete documentation index at: https://python4ai.codewithsiva.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Comments

> Document your code for humans

## 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:

```python theme={null}
# This is a comment
print("Hello")  # This is also a comment

# You can have multiple lines
# of comments by starting
# each line with a hash

age = 25  # Store user's age
```

## Multi-line comments

For longer explanations, use triple quotes:

```python theme={null}
"""
This is a multi-line comment.
It can span several lines.
Great for longer explanations.
"""

def calculate_tip(bill):
    """
    Calculate 20% tip for a restaurant bill.
    Takes the bill amount and returns the tip.
    """
    return bill * 0.20
```

<Note>
  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!
</Note>

## When to use comments

**Good comments explain WHY, not WHAT:**

```python theme={null}
# Good: Explains why
# Using 1.0625 because sales tax in CA is 6.25%
total = subtotal * 1.0625

# Bad: States the obvious
# Multiply subtotal by 1.0625
total = subtotal * 1.0625
```

## Best practices

<Tip>
  Use descriptive variable names instead of comments when possible. `days_in_week = 7` is clearer than `d = 7  # days`.
</Tip>

## Temporary comments

Use comments to disable code temporarily:

```python theme={null}
print("Starting process...")
# print("Debug info")  # Uncomment for debugging
new_method()
# old_method()  # Keeping for reference
```

## Common mistakes

<AccordionGroup>
  <Accordion title="Outdated comments">
    ```python theme={null}
    # Bad: Says 15% but does 20%
    # Calculate 15% tip
    tip = bill * 0.20

    # Good: Accurate
    # Calculate 20% tip (standard)
    tip = bill * 0.20
    ```
  </Accordion>

  <Accordion title="Over-commenting obvious code">
    ```python theme={null}
    # Bad: Too obvious
    x = 5  # Set x to 5
    y = 10  # Set y to 10

    # Good: Only explain complex parts
    x = 5
    y = 10
    position = x + y  # Convert to linear index
    ```
  </Accordion>
</AccordionGroup>

## What's next?

Now that you know the basics and how to document your code, let's explore the different types of data Python can work with!

<Card title="Data types" icon="shapes" href="/data-types">
  Numbers, text, and more
</Card>
