---
description: >-
  This is a short bit about functions. If you're confident in your knowledge of
  functions, skip on ahead!
---

# Preface

Actually, let's not think about functions for a minute; instead, let's think about something fantastic.

![](https://aaron_chen.gitbooks.io/divide-and-conquer/content/assets/push1.png)

Once upon a time, there existed a mysterious race of cats that live forever.. Maybe they live forever because they're really a drawing of my roommate's plushy.

Anyway, this one cat in particular **wasn't given a name** by his parents. He was a young and wild and free spirit, and he was special in that **if you gave him food, he would meow at you**.

This cat travelled all over the world, and the people he met there **gave him names**. When he swung round the north pole....

![](https://aaron_chen.gitbooks.io/divide-and-conquer/content/assets/push2.png)

...they called him Claus.

When he trekked through America...

![](https://aaron_chen.gitbooks.io/divide-and-conquer/content/assets/push3.png)

....they called him Abe.

But whether he was known as Abe or Claus or known by no name at all, he was still the same cat. The same cat that would accept food and **return** a meow.

### Functions <a href="#functions" id="functions"></a>

If you haven't realized yet, our immortal cat was an analogy of a **function**.

He starts out like a **lambda** function: nameless.

```python
lambda food: meow
```

This function, although having no name, accepts **food** as a parameter, and **returns a meow**.

Even though immortal-cat has no name, he can still meow for us:

```python
(lambda food: meow)(cat_food) #returns a meow
```

This passes **cat\_food** into the **food** parameter, and then **returns** a meow.

When our immortal cat swung by the north pole, they named him Claus.

```python
claus = lambda food : meow
```

Now, we can call Claus by name, and give him food that way.

```python
claus = lambda food : meow
claus(cat_food) #returns a meow
```

In America, where they're a bit more advanced, they called him Abe. But they did so in a different way:

```python
def abe(food):
    return meow
```

Our immortal cat accepts **food** as a parameter, and **returns a meow.** His name is now abe. But it's still (basically) the same cat.

```python
def abe(food):
    return meow

abe(cat_food) #returns a meow
```

Concretely, functions are **objects just like any other**. We can name them, rename them, compare them, and even **return** them. That's an important foundation for functional programming.\
