Ojasa Mirai

Ojasa Mirai

Python

Loading...

Learning Level

🟒 BeginnerπŸ”΅ Advanced
Why Functions?Parameters & ArgumentsReturn StatementsScopeDefault ParametersVariable Arguments (*args)Lambda FunctionsDecoratorsFunctional ProgrammingBest Practices
Python/Functions/Parameters Arguments

πŸ“₯ Parameters & Arguments β€” Giving Functions Data

Parameters let you pass different data into functions so they can work with different inputs.


🎯 What are Parameters?

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' parameter

Parameter = The label in the function (`name`)

Argument = The actual value you pass (`"Alice"`)


πŸ’‘ Simple Example

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: 30

πŸ“ Multiple Parameters

Functions 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 York

🎨 Real-World Example: Pizza Order

def 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 mushroom

Without parameters, you'd need a different function for each pizza type!


βœ… Parameter Rules

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"

πŸ”‘ Key Takeaways

ConceptRemember
ParameterThe label inside the function
ArgumentThe actual value you pass in
Order mattersArguments go in the same order as parameters
Multiple parametersSeparate with commas

πŸ”— What's Next?

Now let's learn how to get results back from functions using return statements!

Next: Return Statements β†’


Ready to practice? Try challenges or view solutions


Resources

Python Docs

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

Courses

PythonFastapiReactJSCloud

Β© 2026 Ojasa Mirai. All rights reserved.

TwitterGitHubLinkedIn