Course contents0/6 done

Writing your own functions

def, parameters, return values and default arguments.

Lesson 6 of 6 10 min

You will learn

  • Define and call a function
  • Return a value
  • Use default parameter values

Define once, use many times

A function is a named recipe. def creates it, the values in brackets are its inputs (parameters), and return sends the answer back.

Python · try it

Output appears here · Ctrl + Enter to run

Checkpoint

1. What does simple_interest(2000, 5, 2) return?

2. Why does is_prime only test divisors while d * d <= n?