Lesson 27 of 4068%
(Progress persistence is disabled until Phase 9)
Python
Beginner
Parameters and Arguments
Pass data into your functions.
Parameters and Arguments
What You’ll Learn
You’ll learn how to pass data, known as parameters, into a function.
Arguments
Information can be passed into functions as arguments. Arguments are specified after the function name, inside the parentheses.
def greet(name):
print(f"Hello {name}!")
greet("Alice")
greet("Bob")
Expected Output:
Hello Alice!
Hello Bob!
Multiple Arguments
You can add as many arguments as you want, just separate them with a comma.
def full_name(first, last):
print(first + " " + last)
full_name("John", "Doe")
Parameter vs Argument
From a function’s perspective:
- A parameter is the variable listed inside the parentheses in the function definition (e.g.,
firstandlast). - An argument is the value that is sent to the function when it is called (e.g.,
"John"and"Doe").
By default, a function must be called with the correct number of arguments. If your function expects 2 arguments, you have to call the function with 2 arguments, not more, and not less.