# Decorator Basics — Python

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

> A function that wraps another function to add behaviour, without changing its code.

## @decorator syntax

A decorator takes a function, returns a new wrapped function. `@decorator` above a `def` is shorthand for `func = decorator(func)`.

```python
def shout(func):
    def wrapper(*args, **kwargs):
        result = func(*args, **kwargs)
        return result.upper()
    return wrapper

@shout
def greet(name):
    return f"hello, {name}"

print(greet("ada"))   # HELLO, ADA
```

## Wrapping, not changing

A decorator is like **gift wrapping** — the function inside is unchanged, but it now comes with extra behaviour around it.
