Python Arena
Step 3 of 5

Parameters and arguments

print prints whatever you give it in the parentheses. Your own functions can take values too. Name a variable in the parentheses of the header, and the function gets a value in it every time it's called:

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


greet("Ada")
greet("Linus")
Output
Hello, Ada!
Hello, Linus!

The variable in the header, name, is a parameter. The value in the call, "Ada", is an argument. When the call runs, the parameter gets the argument as its value, and then the body runs. Each call can give a different argument, so one function does the same work with different values.

The two words are easy to mix up, and people often use them loosely, but the difference is worth knowing: a parameter is the name the function uses inside, and an argument is the value a call gives it from outside.

Any value as an argument

An argument can be any expression: a value written out, a variable, or a calculation. Python works out its value first and passes on the result:

def show_square(number):
    print(f"{number} squared is {number * number}")


show_square(4)
side = 7
show_square(side)
show_square(side + 1)
Output
4 squared is 16
7 squared is 49
8 squared is 64

In the call show_square(side), the parameter number gets the value of side, 7. The names don't have to match: the function only ever sees the value.

Inside the body, a parameter is a variable like any other. You can use it in a calculation, an if, a loop or an f-string, and even change it: the change stays inside the function.

A missing argument

A function with a parameter needs an argument in every call:

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


greet()
Python stops with
Traceback (most recent call last):
  File "main.py", line 5, in <module>
    greet()
    ~~~~~^^
TypeError: greet() missing 1 required positional argument: 'name'

The message names the function and the parameter that got no value. "Positional" means that arguments are matched to parameters by their position, first to first. That matters as soon as a function has more than one parameter, in the next step.

Your task

Challenge 1 of 3

Fill in the parameter so the function greets the guest it's called with. A call welcome("Grace") should print:

Welcome, Grace!
Your table is ready, Grace.

Challenge 2

Write a function underline(text) that prints the text and, on the line under it, as many = characters as the text has. A call underline("Hello") prints:

Hello
=====

Challenge 3

Write a function countdown(start) that prints the numbers from start down to 1 on one line, each followed by a space, and then Go!. A call countdown(3) prints:

3 2 1 Go!

With 0 as the argument, it prints only Go!.