mailwal

Python From Scratch #32 - Function Parameters and Arguments

Shefali Jangid

Python From Scratch #32 - Function Parameters and Arguments

Learn how to pass information to your functions using parameters, positional arguments, and keyword arguments.

Hey 👋

In the last lesson, we learned how to create and call functions.

Our functions were able to perform a task, but they always worked with the same information.

What if we want to give a function different information each time we call it?

That’s where parameters and arguments come in.

What Is a Parameter?

A parameter is a variable that you define inside the parentheses when creating a function.

For example:

def greet(name):
    print("Hello", name)

Here, name is a parameter.

It gives the function a way to receive information.

Now we can call the function with different names:

greet("Shefali")
greet("John")

# Output:

# Hello Shefali
# Hello John

The function stays the same, but the information it works with changes.

What Is an Argument?

An argument is the actual value you pass to a function when you call it.

In this example:

greet("Shefali")

"Shefali" is the argument.

So:

  • def greet(name):, name → parameter

  • greet("Shefali"), "Shefali" → argument

A simple way to remember it:

  • Parameter: The variable in the function definition.

  • Argument: The value you pass when calling the function.

A Function With Multiple Parameters

A function can have more than one parameter.

For example:

def greet(first_name, city):
    print("Hello", first_name)
    print("You are from", city)

Now we can provide both values:

greet("Shefali", "Delhi")

# Output:

# Hello Shefali
# You are from Delhi

Here:

  • first_name is the first parameter.

  • city is the second parameter.

  • "Shefali" is the first argument.

  • "Delhi" is the second argument.

Positional Arguments

When you pass arguments normally, Python matches them to the parameters based on their position.

For example:

def greet(first_name, city):
    print("Hello", first_name)
    print("You are from", city)

greet("Shefali", "Delhi")

Python matches them like this:

  • first_name → “Shefali”

  • city → “Delhi”

The first argument goes to the first parameter and the second argument goes to the second parameter.

That’s why these are called positional arguments.

Order Matters

Because Python matches positional arguments by position, the order matters.

For example:

def introduce(name, age):
    print("Name:", name)
    print("Age:", age)

introduce("Shefali", 27)

# Output:

# Name: Shefali
# Age: 27

But if we change the order: introduce(27, "Shefali")

Python doesn’t know that we meant to put the name first.

It simply follows the positions:

  • name → 27

  • age → “Shefali”

The function receives the values in the order we provide them.

Keyword Arguments

You can also pass arguments by naming the parameter directly.

These are called keyword arguments.

For example:

def introduce(name, age):
    print("Name:", name)
    print("Age:", age)

introduce(age=27, name="Shefali")

# Output:

# Name: Shefali
# Age: 27

Notice that we passed age first and name second.

This works because Python matches the values by parameter name instead of position.

So with keyword arguments, the order doesn’t matter.

This can be especially useful when a function has several parameters and you want to make it clear which value belongs to which parameter.

Mixing Positional and Keyword Arguments

You can also mix positional and keyword arguments:

introduce("Shefali", age=27)

The rule is simple: Positional arguments must come before keyword arguments.

The Number of Arguments Matters

If a function expects two arguments:

def greet(name, city):
    print("Hello", name)
    print("You are from", city)

you need to provide both: greet("Shefali", "Delhi")

If you provide only one: greet("Shefali")

Python raises a TypeError because the required argument is missing.

Similarly, providing too many arguments causes an error: greet("Shefali", "Delhi", "India")

The function only expects two arguments.

So, for now, remember:

When using positional arguments, the number and order of the arguments should match the parameters in the function.

Parameters Can Be Different Data Types

Parameters aren’t limited to strings.

You can pass numbers too:

def add(a, b):
    print(a + b)

add(5, 3)

# Output:

# 8

You can also pass other values you’ve already learned about.

For example:

def show_age(age):
    print("Your age is", age)

show_age(27)

# Output:

# Your age is 27

The function simply receives the value and uses it.

Parameters Make Functions Reusable

This is one of the main reasons parameters are useful.

Without parameters, you might create separate functions:

def greet_shefali():
    print("Hello Shefali")

def greet_john():
    print("Hello John")

That’s unnecessary.

Instead, we can create one function:

def greet(name):
    print("Hello", name)

Then reuse it:

greet("Shefali")
greet("John")
greet("Mark")

# Output:

# Hello Shefali
# Hello John
# Hello Mark

One function can now work with different values.

That’s all for today!

Tomorrow, we’ll learn about default arguments and see how a function can use a default value when you don’t provide one.


If you enjoyed this newsletter, consider sharing it with another developer. And if you have any feedback, I’d love to hear it. It would genuinely mean a lot to me. ❤️


Want to sponsor my work? Let’s talk!

See you tomorrow ✨

- Shefali

Thanks for reading DevBits by Shefali! Subscribe for free to receive new posts and support my work.

If you enjoyed this edition of DevBits, you can support my work here ☕

Buy Me a Coffee

Your support helps me keep creating more developer tips, UI snippets, and helpful content for the community.

© 2026 Shefali Jangid
548 Market Street PMB 72296, San Francisco, CA 94104