Python for Data Analytics • Lesson 16

Functions

Learn how to create reusable blocks of Python code using functions. Work with parameters, arguments, return values, default parameters and practical data analytics examples.

Your progress0%

0 of 8 concepts completed

Complete the activity and related MCQ to unlock the next concept.

Concept 1WHY

What Is a Function?

A function is a reusable block of code that performs one specific task. Instead of writing the same lines over and over, you name them once and call that name whenever you need them.

Learn by Seeing

Wrap a task in a name

def greet():
    print("Hello!")

greet()

def gives the block a name; the name becomes the way to run it.

Interactive Activity

What is the main advantage of a function?

Hint: The point is to write once and call many times.

Python Analyst Mindset

Functions turn one-off work into tools

Once a calculation matters, wrap it in a function. The formula lives in one place, gets a name you can read, and can be called hundreds of times with different data — without ever copying the math.

01

Define

Name the task with def.

02

Parameterize

Pass inputs at call time.

03

Return

Hand the result back.

04

Reuse

Call it anywhere.

Lesson Summary

What you learned

def

Defines a function with a name.

Calling

name() runs the function body.

Parameters & arguments

Parameters are names; arguments are the values you pass.

return

Hands a value back to the caller.

Default parameters

Fallback values when arguments are omitted.

Local scope

Variables created inside a function stay inside it.