6.1 The basic form
A minimal function definition is
def f():
pass
This definition begins with the def
keyword.
Then comes the name of the function, f, an open-close
parentheses pair, and a colon, “:
”. The next line is indented and
begins the function body. Here it is
pass
.
We use pass
where we
must include an action but do not have anything useful to do. Think of it as saying, “look how
I am drawing attention to not doing anything.” For example, I can use pass
in a conditional statement to indicate that I am aware of a processing
option and choose to do nothing. You may use three periods, “...
”, instead of pass
.
Starting from this minimal form, we begin to add and use additional Python features. The function body can be any collection of expressions we want to package together and call repeatedly. Let’s define a function that...