← Python Basics
Lesson 3 of 3
Functions
Watch, read the card, then practise. Defining functions · Parameters and return values · Scope
The video for this lesson is being recorded.
Meanwhile, the notes below and the 60-second cards cover the same ideas.
Practise this topicDefining functions
A function is a named block of code you can run again whenever you need it.
Remember: Defining a function doesn't run it. Calling it does.
Parameters and return values
Parameters pass values into a function; return sends a result back out.
Remember: print shows a value; return hands it back so you can use it.
Scope
Variables made inside a function exist only inside it. That's called local scope.
Remember: Prefer returning a value over changing global variables.
Try the example in Code Lab
def greet():
print("Namaste!")
greet()
greet()