def

noun

say it: “DEF” /ˈdɛf/

The Python keyword, short for define, that starts a new function: def, then the function's name, parentheses and a colon.

What does def do?

def (read "define") is the keyword that starts a function: def, the function's name, its parameters in parentheses and a colon. The indented lines under it are the function's body.

def greet(name):
    print(f"Welcome back, {name}!")

greet("Ana")   # Welcome back, Ana!

In a sentence

  • “After def comes the name you'll call the function by.”
  • “Every function in the step counter starts with def and ends its first line with a colon.”

Level: Apprentice · More Python terms at this level

Updated