Level 1
0 / 100 XP

Section 6 overview

So far you've written code that runs top to bottom. Functions let you package a chunk of code, give it a name, and reuse it whenever you want — instead of copying and pasting.

A function is a named, reusable block of code. You define it once, then call it as many times as you need.

What you'll learn

  • Define and call your own functions
  • Pass data in with parameters and get results back with return
  • Give parameters default values so callers can leave them out
Python
def greet(): print("Hello!") greet() # Hello! greet() # Hello!

Functions keep your programs short, readable, and easy to change — fix the logic in one place and every call gets the fix.

Key takeaways

  • A function is a named, reusable block of code.
  • You define a function once and call it many times.
  • This section covers defining, calling, parameters, return values, and defaults.