Functions are more powerful when you can give them information to work with. This is done through arguments. An argument is a value you pass to a function when you call it. Python then uses that value inside the function. Let’s look at how this works step by step.
Positional arguments
The simplest way to pass arguments is in the order they are defined. These are called positional arguments.
def greet(name, age):
print(f"Hello {name}, you are {age} years old.")
greet("LiddleBit", 25)
Here, “LiddleBit” is matched to name and 25 is matched to age. The order matters.
Keyword arguments
You can also pass arguments using the parameter names directly. These are called keyword arguments.
greet(age=25, name="LiddleBit")
This works even though the order is different, because each value is linked to a name. Using keyword arguments can greatly improve the readability of your code, especially if a function has several parameters. It makes it obvious what each argument means, rather than relying on the reader to remember the order.
Default values
Sometimes you want a parameter to have a default value. This means you can call the function without providing that argument, and Python will use the default instead.
def greet(name, age=18):
print(f"Hello {name}, you are {age} years old.")
greet("LiddleBit") # uses default age of 18
greet("LiddleBit", 25) # overrides the default
Defaults make your functions more flexible, as they work with or without all arguments provided.
Mixing it all together
You can combine positional, keyword, and default arguments, but keep in mind that positional arguments must come first.
def introduce(name, role="student"):
print(f"This is {name}, who is a {role}.")
introduce("LiddleBit") # uses default role
introduce("LiddleBit", role="developer") # overrides role with keyword
Things to try yourself
- Write a function called
favourite_colourthat takes two arguments:nameandcolour. Givecoloura default value. - Write a function called
areathat takeslengthandwidthand prints the area. Try calling it with both positional and keyword arguments. - Write a function called
describe_petwith parametersanimal_type(default “dog”) andpet_name. Call it with different combinations of arguments.
By learning how to use positional arguments, keyword arguments, and default values, you make your functions easier to use and more adaptable. Keyword arguments in particular help your code stay clear and self-explanatory, which is invaluable when projects grow or when other people read your work.




