Key Concepts

Review core concepts you need to learn to master this subject

Returning Multiple Values

def square_point(x, y, z): x_squared = x * x y_squared = y * y z_squared = z * z # Return all three values: return x_squared, y_squared, z_squared three_squared, four_squared, five_squared = square_point(3, 4, 5)

Python functions are able to return multiple values using one return statement. All values that should be returned are listed after the return keyword and are separated by commas.

In the example, the function square_point() returns x_squared, y_squared, and z_squared.

Lesson 1 of 2
  1. 1
    This lesson requires you to know the basics of hamburger-making: * Place the bread down * Add the burger patty * Add the pickles * Place the bread on top What if you had to say each step every tim…
  2. 2
    Instead of giving those instructions for every hamburger, we can group and name them as a single function: function makeHamburger() { Add bread Add burger patty Add pickles Add bread } …
  3. 3
    Not everyone wants to eat hamburgers. We could write a new function for each new sandwich type, but that takes a lot of work and risks making mistakes. Instead, we’ll generalize the hamburger f…
  4. 4
    A sandwich wouldn’t be complete without fries and dessert! Here are the instructions to make the complete meal: * Add bread, Add burger patty, Add fried potatoes, Add pickles, Add bread, Add salt…
  5. 5
    Time to get coding! It’s okay if you don’t recognize all the symbols in this code: we’ll walk you through the parts you need to know. The makeSandwich() function is provided in main.js. It is …
  6. 6
    Well done! Functions are a fundamental concept in programming, and learning the basics will serve you wherever your path leads, regardless of language or domain. To review: * A function is a sequ…