Python · Stage 6 – Reusable Code · Lesson 34 of 50

Defining Functions, Parameters, and Returns

Create one function that receives information and sends a result back.

def double(number):
    result = number * 2
    return result
Line-by-line explanation
  1. def begins the function named double.
  2. number is its parameter.
  3. The indented calculation creates a result.
  4. return sends that result back.
answer = double(4)
Line-by-line explanation
  1. The function is called with 4.
  2. Inside the function, number receives 4.
  3. The returned value 8 is stored in answer.