Previous topic

4. Counting on recursion

Next topic

1. Many names for the same object

This Page


At the very beginning of this tutorial, we wrote the following:

move() is an example of a Python function. A function has a name; in this case, it is move. Valid names must start with either a letter or the underscore character “_” and may contain letters, numbers or the underscore character “_”. The name of the function is followed by (). This tells Reeborg (Python) that the function must be executed or called (which are two synonyms).

Functions are an example of what we call an object. We can give one or many names to a given object. We call variable the name that we give to an object. Python uses the equal sign = to associate a name (variable) and an object in the following way:

variable = object

For example, if you find that turn_left() is too long to write, you could define another name (variable) for it as follows:

left = turn_left    # no parentheses!
left()              # use it

Your turn!

Use a new name (variable) for at least one existing function in a program. Can you use two different names to refer to the same object in a single program?