S
Seoffix.com
Sign In Get Pro Membership

Python Foundations

Writing Functions

Beginner Python 30 XP

Writing Functions

A function packages steps behind a name. Use def, list the inputs, and return the result.

Example

def double(n):
    return n * 2

print(double(4))

Your task

Write add(a, b) that returns the sum and print add(2, 3).

Hints

  1. Use return, not print, inside the function
  2. return a + b

Check your understanding

Answer every question to pass.
1. Which keyword sends a value back from a function?

Your answer

This lesson is checked against the lesson rules. Your code is never run on our servers.

AI Code Explainer & Translator

Runs without any outside service.
 
Mark Complete & Earn XP
Earn 30 XP after you pass the quiz. Finish every lesson in the track to earn its certificate.
Sign in to earn XP