How Logic Works

Function

A reusable block of code that performs a specific task.

Definition

A reusable block of code that performs a specific task. You give it a name, define what it does, and then call it whenever you need that task done. Functions prevent you from writing the same code over and over.

Example

def calculate_average(numbers): return sum(numbers) / len(numbers) — this function takes a list of numbers and returns their average. You can call it anywhere in your program.

See it in context Learn how Function fits into the bigger picture of how software actually works.

Read the Guide →