# Function calls

## Function calls

In this lesson you will learn:

- what a function is
- how to call a function
- why functions are useful

## Function examples

Here are some examples of functions:

- the
`print`

function outputs text to the screen - the
`len`

function gives you the length of a string - the
`min`

function finds the smaller of two or more numbers

We'll explain exactly what a function is after you have had a chance to experiment with some examples.

## Example: len

The code box has an example of using the `len`

function to find the length of
the string `"test"`

. Run it to continue.

## Try using len

Try to change the code so it computes the length of the string
`"hello world"`

using `len`

and then prints out the length.

## Example: min

Here is an example of using the `min`

function:

```
smallest = min(3, 4)
print(smallest)
```

Note that `min(3, 4)`

gives you the smaller number, which is `3`

. That number
is then stored in the variable `smallest`

, and that variable is then printed.

Here's another way to do the same:

```
print(min(3, 4))
```

## Try using min

Try to change the code so it uses `min`

to compute the smallest of the
numbers 4 and 7.

## What is a function?

If you've never heard of functions before, you can think of a function as a machine that you put something into. The machine does some work, and out comes a result.

For `min`

, you put two numbers into the machine and one comes out.

For `len`

you put a string into the machine and a number comes out.

For `print`

you put a string into the machine and nothing comes out -- but
the machine shows the text on your screen.

## What is a function?

You may also know about functions from mathematics. For example, in math we might write f(x) = x+2.

Here, f is an example of a function.

## Terminology

It's worth knowing that some programmers also speak of functions as "procedures" or "methods". If you substitute "function", you will understand them anyway.

When you use a function, programmers say that you "call" or "invoke" the function.

As an example, earlier you called the `len`

and `print`

functions.

The values you put into a function are referred to as "arguments".

## Try using min from scratch

The `min`

function works on numbers, not strings.

The numbers we put into `min`

are referred to as "arguments" to the function
call.

To continue, call the `min`

function, giving it `0`

and `1`

as arguments. Save
the result in a variable. Then print out the variable.

Here are two examples of calling `min`

that you can use as a basis for your
solution:

```
z = min(1, 2)
small_number = min(8, 2, -5, -4)
```

## Why do we need functions?

You've seen `print`

, `len`

and `min`

. These are called "built-in functions".
This means that they were written by the creators of Python for you to
conveniently use in any Python program. Other programming languages have
different built-in functions.

Knowing about these functions gives you access to useful functionality, so they are worth remembering.

Even if you don't remember precisely what
`len`

was called, now you know it exists, and you can always google, say, "how
to find the length of a string in python" to find out again.

## Why do we need functions?

In the next lesson you'll learn how to create your own functions that you can call anytime you want.

Once you've written the functions you need, you can quickly piece them together to accomplish a lot in no time.