PYTHON CORE · LESSON 20

Function with response

Argument and return · about 15 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

Pass the number of the function

In brackets, after the function name, the incoming number can be called. When you call, transmit your meaning.

def double(number):
    print(number * 2)
double(3)

✦ The function will get 3 and show 6.

STEP 2

Return the answer.

return gives the result to the outside. It can then be saved or displayed via print.

def double(number):
    return number * 2
print(double(3))

✦ 6 will appear again, but now the function has returned the number.

IN-CLASS PRACTICE

Type the code yourself

Reprint the function. Don't forget to back off before return.

def triple(number):
    return number * 3
print(triple(4))
Open the editor for class work
HOMEWORK

Solve it yourself

Create add_two with the number argument. Let it return number plus 2. Call it with the number 5 and output the answer.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework