Arguments

We have seen one function already, print(), which outputs a message. To use a function you always write its name, followed by zero or more arguments in parentheses (); this is called the argument list. The word argument basically means an input to the function. Then, the function does some action depending on its arguments. When there are multiple arguments to a function, you separate them with commas (,). For example, if you give multiple arguments to print(), it will print all of them in order, with spaces separating them. We demonstrate in the example below.

Functions don’t always have to take in arguments. However, if a function requires an argument, or many arguments, and you don’t provide them then you will receive an error.

Common Errors

If you call a function without enough arguments (inputs) or too many arguments, you get an error. For example, max requires at least one argument:

line 1
    max()
TypeError: max expected 1 arguments, got 0

The code above tells us that on line 1 a function called max() was used.

The error says that max expected 1 argument but instead got 0 arguments.

It’s very important to carefully read the errors that you get back when your code doesn’t work. Python will usually give you helpful feedback on what went wrong. However, sometimes you need to look around a little bit to diagnose the problem — here’s an example.

Python says there is a syntax error, which means it can’t understand what you’re trying to do:

line 2
    bigger = max(3, 4)
         ^
SyntaxError: invalid syntax

However, the line bigger = max(3, 4) is actually fine. The problem actually spilled over from the previous line: we forgot to add the closing parenthesis ) after smaller = min(14, 99 and Python started looking at the next line for the closing ). So, check the lines before and after what Python suggests, if you are stuck debugging your programs.