Notes / Python / Functions

Functions in Python — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 Functions Python functions are defined with the def keyword.

Syntax

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

Example

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

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

Output

outputSum: 11

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview A well-known intermediate Python gotcha: mutable default arguments (e.g. def f(x=[]):) are shared across calls — be ready to explain why and how to avoid it (use None as the default instead).
Back to notes Read full lesson →