Learn 2: Classes and Instances

4. Functions and Arguments

So far, you’ve learned how to instruct the orienteer using commands such as orienteer.open_eyes().

What if we wanted to tell the robot to drive forward a particular distance, say, 50cm? Well, as it happens, we have an EasyGoPiGo3 class library function for that:

orienteer.drive_cm(50)


Notice how this function has a value inside its brackets where open_eyes() didn’t.

With this type of instruction, the function name identifies the action to be taken (driving forwards a set distance, measured in cm) and the number inside the brackets identifies how the action should be performed (in this case, the exact distance to travel).

You can think of this type of instruction like an English instruction, with the function name being the verb and the value in the brackets acting like an adverb. Can you see why the open_eyes() function doesn’t need any values in its brackets?

NOTE:

In the computing industry, any values that are supplied to a function inside its brackets are often referred to as function arguments.