OOP – Classes & Objects, online

Six activities your students do on their own devices. See who's finished, and their scores.

OOP – Classes & Objects in one minute

What students need to know

A class is a blueprint that defines the structure of a group of objects — what data they hold and what they can do. An object (also called an instance) is a specific thing created from that class, using the class's name like a function: Dog('Rex'). Inside a class's methods, self refers to the particular object the method is being called on, which is how each object keeps its own separate data.

Mistakes students make

  • class must be written lowercase — Class Dog: is invalid Python, even though it looks like a small typo.
  • Forgetting self as the first parameter of a method is another common early mistake, since Python doesn't add it automatically.

Discover other journeys with this module

What students will learn in this module

Every question in Module 49

Quick questions

  1. What is a class?AA blueprint for creating objectsBA function
  2. What is an object?AA class definitionBAn instance created from a class
  3. How do you create an object?Amy_obj = ClassName()Bdef ClassName():
  4. What does 'self' refer to?AThe current object instanceBThe class itself
  5. class Dog:\n pass\ndog = Dog()\nWhat is dog?AThe Dog classBAn instance of the Dog class

Key terms

Students type the meaning of:

  • Class
  • Object
  • Instance
  • self

Match the pairs

class dog:
    pass
Match it to what it does
class Dog
    pass
Match it to what it does
class Dog:
    pass
d = Dog()
Match it to what it does
class Car:
    pass
a = Car()
b = Car()
Match it to what it does
class Dog:
    pass
d = Dog()
print(type(d))
Match it to what it does
class Cat:
    pass
c = Cat()
c.name = 'Mia'
print(c.name)
Match it to what it does

Fill in the blanks

  1. _____ Dog:
        pass
  2. class Dog:
        pass
    
    my_dog = ___()
  3. p = Person()
    p.____ = 'Alice'
  4. class Car:
        ____
  5. print(____(my_dog))

Spot the error

Question 1

AClass Dog:B    def __init__(self, name):C        self.name = nameD    def bark(self):E        return 'Woof!'

Question 2

Aclass dog:B    def __init__(self, name):C        self.name = nameD    def bark(self):E        return 'Woof!'

Question 3

Aclass DogB    def __init__(self, name):C        self.name = nameD    def bark(self):E        return 'Woof!'

Question 4

Aclass Dog():B    passCDmy_dog = Dog

Question 5

Adef Dog:B    def __init__(self, name):C        self.name = nameD    def bark(self):E        return 'Woof!'