Python · Stage 9 – Intro to Objects · Lesson 45 of 50

Classes and Objects

Understand a class as a blueprint and an object as one created instance.

class Dog:
    pass
Line-by-line explanation
  1. class begins a class definition.
  2. Dog is the class name.
  3. The colon begins its indented body.
  4. pass is a do-nothing placeholder.
pet = Dog()
Line-by-line explanation
  1. Dog() creates one instance.
  2. pet stores that object.

Tiny Practice

Create one object from the empty Book class.

Starter template

class Book:
    pass

my_book = CHANGE_ME
Line-by-line explanation
  1. The class is already defined.
  2. The missing expression creates an instance.
Hint
  1. Use the class name.
  2. Add round brackets.
  3. Do not use quotes.
Show Solution
class Book:
    pass

my_book = Book()
Line-by-line explanation
  1. The class defines a blueprint.
  2. Book() creates an instance.
  3. my_book stores it.