Cement your knowledge of objects

So far, we have learnt that an object has attributes (or pieces of data) stored inside it, and methods we can call on it to give it instructions.

Do you remember when we added this line of code in the turtle program?

from turtle import Turtle

This line told Python that we would like to import the Turtle class so we can use it to make Turtle objects. Did you notice that I used a capital ‘T’ when referring to the Turtle class, but I didn’t use a capital letter in the name I gave the object?

laura = Turtle()

This was because class names usually start with a capital so that they are easily distinguishable from variable names.

As I briefly mentioned earlier, a class is like a blueprint for creating objects. I like to think of a class as being similar to a cookie cutter – it is a template for all the cookie objects you make. You can make as many instances of cookie objects as you want, and they will all start off from the same template. If you like, you can customise each instance of a cookie object, perhaps by adding some icing or some sprinkles. But whenever you make cookies, you use the same cookie-cutter template.

Share this video:

This video is from the free online course:

Object-oriented Programming in Python: Create Your Own Adventure Game

Raspberry Pi Foundation