# Function

> A named block of code that does one job. Write it once, use it many times.

**Field:** Software Development  
**Category:** Programming Concepts  
**Also known as:** Subroutine, Procedure

## Think of it like

Think of it like a toaster. Bread goes in, you press one button, and toast comes out.

## Definition

A function is a named block of code that does one job. You write it once and then use it as often as you like. It can take values in, called parameters, and hand a result back. Calling it by name runs the code inside. Splitting a program into small functions makes it easier to read, test and fix.

## Example

A shop writes one function, add_tax, that adds 20% to a price. Every page that shows a price calls it.

## Example code

```python
def greet(name):
    return "Hi, " + name + "!"

print(greet("Emma"))   # Hi, Emma!
```

The job is written once, under a name, then used with one line.

## Why it matters

Functions stop you writing the same code twice. Fix a bug in one function and every place that uses it is fixed.

## Common mistake

Writing one huge function that does ten jobs. Small functions with clear names are far easier to follow.

## Three principles

- **One job.** A good function does one clear thing.
- **Write once.** Use it from as many places as you like.
- **In and out.** Values go in; a result comes back.

## Related terms

- [Parameter](https://learn.benibix.com/term/development/parameter)
- [Argument](https://learn.benibix.com/term/development/argument)
- [Return Value](https://learn.benibix.com/term/development/return-value)
- [Function Call](https://learn.benibix.com/term/development/function-call)
- [Scope](https://learn.benibix.com/term/development/scope)
- [Built-in Function](https://learn.benibix.com/term/development/built-in-function)
- [Module (Programming)](https://learn.benibix.com/term/development/module)

## Told apart from

- [Method vs Function](https://learn.benibix.com/compare/method-vs-function): A method is a function too, but it belongs to an object. A plain function stands alone; a method is called with a dot and can use its object's data.

## Taught in

- [Functions in Python](https://learn.benibix.com/learn/development-concepts/functions-in-python): Programming Basics, 12/18

---

Source: https://learn.benibix.com/term/development/function
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
