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 and Arguments

Learn the difference between parameters and arguments, and how to make functions flexible by accepting data.


🎯 Parameters vs Arguments

These terms are often confused, but understanding the distinction is crucial for writing flexible code. Parameters are the placeholders you define in the function definitionβ€”they're the "slots" waiting to receive data. Arguments are the actual values you pass when calling the functionβ€”they're the data that fills those slots.

def greet(name):           # 'name' is a PARAMETER
    print(f"Hello {name}!")

greet("Alice")             # "Alice" is an ARGUMENT

πŸ”§ How Parameters Work

Single Parameter

def greet(name):
    print(f"Hello {name}!")

greet("Alice")    # Pass "Alice"
greet("Bob")      # Pass "Bob"
greet("Charlie")  # Pass "Charlie"

Output:

Hello Alice!
Hello Bob!
Hello Charlie!

Multiple Parameters

def greet_person(name, age):
    print(f"Hello {name}!")
    print(f"You are {age} years old.")
    print("Welcome to our course!")

greet_person("Alice", 25)
greet_person("Bob", 30)

Output:

Hello Alice!
You are 25 years old.
Welcome to our course!
Hello Bob!
You are 30 years old.
Welcome to our course!

πŸ“Š Parameter Order Matters

When you call a function, Python matches arguments to parameters based on their position from left to right. The first argument you pass goes to the first parameter, the second argument to the second parameter, and so on. This positional matching means that passing arguments in the wrong order will produce incorrect results or type errors, so parameter order is critical.

def introduce(first, last, age):
    print(f"{first} {last} is {age} years old")

# Correct order
introduce("John", "Doe", 30)      # βœ…

# Wrong order gives wrong results
introduce("30", "Doe", "John")    # ❌ Weird output!

πŸ’‘ Real-World Examples

Calculate Area of a Rectangle

def calculate_area(length, width):
    area = length * width
    print(f"Length: {length}, Width: {width}")
    print(f"Area: {area}")

calculate_area(5, 10)   # Area: 50
calculate_area(3, 7)    # Area: 21

Calculate Average

def show_average(num1, num2, num3):
    average = (num1 + num2 + num3) / 3
    print(f"Numbers: {num1}, {num2}, {num3}")
    print(f"Average: {average}")

show_average(85, 90, 88)
show_average(100, 95, 92)

🎨 Make Functions Flexible

Parameters are what make functions truly powerful and reusable. Without parameters, a function is hardcoded for specific values and must be edited every time you need different data. With parameters, a single function becomes a template that works with infinite variations of input, making your code DRY (Don't Repeat Yourself) and maintainable.

Without Parameters (Not Flexible)

def show_score():
    score = 85
    print(f"Your score: {score}")

This only works for score 85. To use a different score, you'd need to modify the function!

With Parameters (Flexible)

def show_score(score):
    print(f"Your score: {score}")

show_score(85)   # Works for 85
show_score(92)   # Works for 92
show_score(78)   # Works for 78

Same function, different data! Much better! ✨


πŸ“‹ Naming Parameters

Choose descriptive parameter names:

# βœ… Good - Clear names
def calculate_total(price, tax_rate):
    total = price + (price * tax_rate)
    return total

# ❌ Bad - Unclear names
def calculate_total(a, b):
    total = a + (a * b)
    return total

πŸ› Common Mistakes

Wrong Number of Arguments

def greet(name, age):
    print(f"{name} is {age}")

greet("Alice")        # ❌ Missing age argument!
greet("Bob", 30, "ok") # ❌ Too many arguments!
greet("Charlie", 25)  # βœ… Correct!

Type Mismatches

def add_numbers(a, b):
    return a + b

add_numbers(5, 3)           # βœ… Works
add_numbers("5", "3")       # Returns "53" not 8!
add_numbers(5, "3")         # ❌ Error!

βœ… Best Practices

1. Use clear parameter names β€” Self-documenting code

2. Keep functions focused β€” Not too many parameters

3. Parameter order matters β€” Be consistent

4. Document parameters β€” Tell users what each does

def send_email(to, subject, message):
    """
    Send an email.

    to: Email address (string)
    subject: Email subject (string)
    message: Email body (string)
    """
    print(f"Sending email to {to}")
    print(f"Subject: {subject}")
    print(f"Message: {message}")

🎯 Key Takeaways

ConceptRemember
ParametersVariables in function definition
ArgumentsActual values when calling
PositionArguments matched by position
FlexibilityParameters make functions reusable
ClarityUse descriptive parameter names
CountProvide correct number of arguments

πŸ”— What's Next?

Now that functions can accept data via parameters, let's learn how to send data BACK from functions using return statements.

Next: Return Statements β†’


Practice: Try challenges with parameters


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