Search⌘ K

Passing Arguments to a Function

Explore how to define functions in Python that accept arguments and how to call them using positional or keyword arguments. Understand the importance of matching argument names and how to capture and use the return value. This lesson prepares you to handle common errors when passing arguments.

We'll cover the following...

Now we’re ready to learn about how to create a function that can accept arguments and also learn how to pass said arguments to the function. Let’s create a simple function that can add two numbers together:

Python 3.5
def add(a, b):
return a + b
print(add(1, 2)) # 3

All functions return something. ...