# Defining Functions — Python

Source: https://www.geekswithgeeks.com/en/python/py-functions-basics

> Package reusable logic behind a name with `def`.

## def and return

`def` starts a function. `return` sends a value back; without it, the function returns `None`.

```python
def area(width, height):
    return width * height

print(area(4, 5))   # 20
```

## Default arguments

**Default arguments** make a parameter optional by giving it a fallback value.

```python
def greet(name, greeting="Hello"):
    return f"{greeting}, {name}!"

print(greet("Ada"))
print(greet("Ada", "Hi"))
```

## Mutable default pitfall

Never use a mutable object like `[]` or `{}` as a default argument — it's created **once** and shared across calls.
