Curriculum / Python / Lesson 08

Functions in Python

Python functions are defined with the def keyword.

8 of 11
beginner 📖 5 min read 🎯 1 question

Functions

Python functions are defined with the def keyword. They can accept parameters (including default values), and return a value with return — or return nothing at all (None) if no return is used.

💡 Key insight A Python function with no explicit return statement automatically returns None.

Syntax

syntax
def functionName(param1, param2=defaultValue):
    # code
    return value

Example

Calling add(4, 7) runs the function body and gives back the value after return.

py
def add(a, b):
    return a + b

result = add(4, 7)
print("Sum:", result)
outputSum: 11

Try it yourself

Copy this example into the Python compiler and run it — try changing a value and see what happens.

Quick Quiz

1. What does a Python function return if it has no explicit return statement?

Back to curriculum