Chapter 5: Advanced function features

Positional arguments

face Josiah Wang

Everything we have discussed so far can be applied to most programming languages.

In this chapter, I will talk about some features specific to Python functions. This will give you more flexibility and power when implementing functions in Python.

Let us look at some problems with a basic ‘vanilla’ function implementation.

In its basic form, you can supply any number of parameters. The parameters can be of any type.

def do_something(a, b, c, d, e, f, g, h, i, j):
    print(f"{a}; {b}; {c}; {d}; {e}; {f}; {g}; {h}; {i}; {j}")
    return None

However, calling the function with every single argument might be a bit too much to ask of a user.

x = do_something(8, "fine", "really?", "do I have to?", "help!", 
                444, "no more!", "arghh!", "kill me now", "zzz...")

These type of arguments are called positional arguments. Python will assign arguments to parameters by matching their position. So the first argument goes to a, the second argument goes to b, etc.