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

# Variables

> Learn to store and name your data

## What are variables?

A variable is like a labeled box where you can store information. You give it a name and put a value inside. Later, you can use that name to get the value back.

In real life:

* Your name is a "variable" that stores what people call you
* Your age is a "variable" that stores a number
* Your favorite color is a "variable" that stores text

In Python, we create variables to store data our programs need to remember.

## Creating your first variable

Here's how to create a variable:

```python theme={null}
name = "Alice"
age = 25
is_student = True
```

Let's break this down:

* `name` is the variable name
* `=` means "store the value on the right in the variable on the left"
* `"Alice"` is the value we're storing

## Naming rules

Python has rules for variable names:

**Allowed:**

```python theme={null}
user_name = "Dave"      # lowercase with underscores (Python style)
userName = "Dave"       # camelCase (works but not Python style)
age2 = 30              # numbers are OK (not at start)
_private = "secret"    # underscore at start is OK
```

**Not allowed:**

```python theme={null}
2age = 30              # Can't start with number
my-name = "Dave"       # No hyphens (Python thinks it's subtraction)
my name = "Dave"       # No spaces
class = "Python"       # Can't use Python keywords
```

### Python naming convention

In Python, we use lowercase letters with underscores between words. This is called "snake\_case" and it's the standard way to name variables in Python.

```python theme={null}
# Good Python style
first_name = "Alice"
user_age = 25
is_logged_in = True
shopping_cart_total = 49.99

# Avoid camelCase (this is for other languages)
firstName = "Alice"  # Works, but not Python style
userAge = 25
isLoggedIn = True
```

<Tip>
  Use descriptive names for your variables! Instead of `x` or `temp`, use names like `user_score` or `file_path`. Your future self (and teammates) will thank you when reading the code later.
</Tip>

## Changing variables

Variables can change (that's why they're called variables!):

```python theme={null}
# Start with one value
score = 0
print(score)  # Shows: 0

# Change it
score = 10
print(score)  # Shows: 10

# Change it again
score = score + 5
print(score)  # Shows: 15
```

## Common mistakes

<AccordionGroup>
  <Accordion title="Forgetting quotes around text">
    ```python theme={null}
    # Wrong
    name = Alice  # Python looks for a variable called Alice

    # Right
    name = "Alice"  # This creates text
    ```
  </Accordion>

  <Accordion title="Using undefined variables">
    ```python theme={null}
    # Wrong
    print(score)  # Error: score doesn't exist yet
    score = 10

    # Right
    score = 10
    print(score)  # Now it works
    ```
  </Accordion>

  <Accordion title="Confusing = and ==">
    ```python theme={null}
    # = means "store"
    age = 25

    # == means "compare" (we'll learn this later)
    if age == 25:
        print("Quarter century!")
    ```
  </Accordion>
</AccordionGroup>

## What's next?

Before we explore data types, let's learn about comments - a crucial tool for making your code readable.

<Card title="Comments" icon="comment" href="/basics/comments">
  Document your code clearly
</Card>
