
Python
Parameters let you pass different data into functions so they can work with different inputs.
A parameter is like a mailbox on your function that receives data when someone calls it. Parameters allow the same function to work with different data each time you call it. When you define a parameter in the function definition, you're saying "I want to receive some data here called [parameter name]."
def greet(name):
print(f"Hello, {name}!")
greet("Alice") # "Alice" goes into the 'name' parameter
greet("Bob") # "Bob" goes into the 'name' parameterParameter = The label in the function (`name`)
Argument = The actual value you pass (`"Alice"`)
Here's a function that takes two values, does something with them, and produces a result. Notice how the same function works perfectly with different numbers each time you call it. This is the power of parametersβyou write the logic once, and it works with unlimited different inputs.
def add_two_numbers(a, b):
result = a + b
print(result)
add_two_numbers(5, 3) # Output: 8
add_two_numbers(10, 20) # Output: 30Functions can accept multiple parameters separated by commas. When you call the function, you pass arguments in the same order as the parameters. This lets you create functions that handle complex data and scenarios by accepting several different pieces of information.
def introduce(name, age, city):
print(f"My name is {name}")
print(f"I am {age} years old")
print(f"I live in {city}")
introduce("Sarah", 25, "New York")Output:
My name is Sarah
I am 25 years old
I live in New Yorkdef order_pizza(size, topping):
print(f"You ordered a {size} pizza with {topping}")
order_pizza("large", "pepperoni") # Output: You ordered a large pizza with pepperoni
order_pizza("small", "mushroom") # Output: You ordered a small pizza with mushroomWithout parameters, you'd need a different function for each pizza type!
1. Parameters go in parentheses after the function name
2. Separate multiple parameters with commas
3. Pass arguments in the same order as parameters
def describe_pet(animal, name):
print(f"{name} is a {animal}")
describe_pet("dog", "Max") # Correct: animal="dog", name="Max"
describe_pet("cat", "Whiskers") # Correct: animal="cat", name="Whiskers"| Concept | Remember |
|---|---|
| Parameter | The label inside the function |
| Argument | The actual value you pass in |
| Order matters | Arguments go in the same order as parameters |
| Multiple parameters | Separate with commas |
Now let's learn how to get results back from functions using return statements!
Ready to practice? Try challenges or view solutions
Resources
Ojasa Mirai
Master AI-powered development skills through structured learning, real projects, and verified credentials. Whether you're upskilling your team or launching your career, we deliver the skills companies actually need.
Learn Deep β’ Build Real β’ Verify Skills β’ Launch Forward