# Functions

Learn about code reuse with Python functions. Apply that knowledge to create functions for famous physics formulas.

Start## Key Concepts

Review core concepts you need to learn to master this subject

Returning Multiple Values

The Scope of Variables

Function Parameters

Multiple Parameters

Returning Value from Function

Functions

Function Indentation

Calling Functions

Returning Multiple Values

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`

.

Introduction to Functions

Lesson 1 of 1

- 1In programming, as we start to write bigger and more complex programs, one thing we will start to notice is we will often have to repeat the same set of steps in many different places in our progra…
- 2Let’s come back to the trip planning application we just discussed in the previous exercise. The steps we talked about for our program were: 1. Establish an origin and destination 2. Calculate …
- 3A
*function*consists of many parts, so let’s first get familiar with its core - a function definition. Here’s an example of a function definition: def function_name(): # functions tasks go he… - 4Now that we’ve practiced defining a function, let’s learn about calling a function to execute the code within its body. The process of executing the code inside the body of a function is known as …
- 5Consider our welcome function for our trip planning application: def trip_welcome(): print(“Welcome to Tripcademy!”) print(“Let’s get you to your destination.”) The print statements all ru…
- 6Let’s return to our trip_welcome() function one more time! Let’s modify our function to give a welcome that is a bit more detailed. def trip_welcome(): print(“Welcome to Tripcademy!”) print(“L…
- 7Using a single parameter is useful but functions let us use as many parameters as we want! That way, we can pass in more than one input to our functions. We can write a function that takes in mor…
- 8In Python, there are 3 different types of arguments we can give a function. * Positional arguments: arguments that can be called by their position in the function definition. * Keyword arguments…
- 9There are two distinct categories for functions in the world of Python. What we have been writing so far in our exercises are called
*User Defined Functions*- functions that are written by users … - 10As we expand our programs with more functions, we might start to ponder, where exactly do we have access to our variables? To examine this, let’s revisit a modified version of the first function we…
- 12Sometimes we may want to return more than one value from a function. We can return several values by separating them with a comma. Take a look at this example of a function that allows users in our…

## What you'll create

Portfolio projects that showcase your new skills

## How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory