dreamcode
Back to map
Functions · Lesson 4 of 6
+15 XP on finish
PYTHON BASICS

Wrap it in a name

A function is a named bundle of steps. Define it once with def, then call it by name whenever you need it. Functions can take inputs in the parentheses and hand back a result with return.

How it reads
def greet(name): defines a function called greet that takes one input, name
The indented body runs only when you call the function
return hands a value back to whoever called it
Cloud tip: Define a function once, call it as many times as you like. That is how you stop repeating yourself.
main.py
PYTHON
real Python, runs in your browser
CONSOLE
- run your code to see output -