✦ Python Intermediate & OOP Intermediate Python

L2 · Concept 01 · OOP Fundamentals

Model the library.
Organize the story.

Mini Library Manager begins by grouping each book’s data and future behavior into a clear model.

Learning goalExplain how object-oriented programming models related data and behavior, and distinguish a class from an object.
01 Learn02 Try03 Predict

Learning as a guest

Learning as a guest? Save your progress!

Create a free account to learn with Sloby AI, check your understanding, and track your progress.

The entire platform is free throughout 2026. Foundations stays free forever.

A library has many related things.

Procedural code can keep a title and author in separate variables or dictionaries. As a library grows, object-oriented programming (OOP) gives each book a shared model, its own data, and later its own behavior.

title_one = "Dune"
author_one = "Frank Herbert"
title_two = "The Hobbit"
author_two = "J. R. R. Tolkien"

These variables work, but the connection between each title and author is something the programmer must keep organized.

A class is a blueprint for similar objects. An object is one concrete instance. In the next lesson, you will define the Book class in detail; for now, notice that each book object can hold its own attributes.

↳

Mini Library Manager: This module will gradually turn the book model into a small library application.

Two independent book objects
class Book:
    pass

book_one = Book()
book_two = Book()
book_one.title = "Dune"
book_two.title = "The Hobbit"
book_one.title = "Dune Messiah"

print(book_one.title)
print(book_two.title)

book_one and book_two come from the same Book class, but changing book_one.title does not change book_two.title.

Data and behavior
book.title = "Dune"
book.author = "Frank Herbert"
# Later, a book can also have behavior, such as borrowing.

Attributes describe an object’s data. Methods will describe behavior in a later lesson.

Follow the model

  1. 1. Find related dataA book has related information such as a title and an author.
  2. 2. Choose a shared modelA class describes what similar book objects have in common.
  3. 3. Create instancesEach object represents one concrete book in the library.
  4. 4. Keep state separateChanging one object’s attributes does not change another object’s attributes.

Common mistakes

  • Treating a class as one bookA class is the shared definition; an object is a particular book.
  • Expecting objects to share every valueInstance attributes belong to the object where they are assigned.
  • Rushing into constructorsFirst understand the model and instance; constructors come in the next lesson.
  • Forgetting the dotUse object.attribute to read or assign data for one object.

Python Playground

Loading Python runtime…

Change a title or author, then add another Book object and give it its own attributes.

mini_library.pyPython
OutputWaiting for Python
The browser runtime is loading. You can still edit the example code.

Pyodide runs Python in a browser Web Worker. It is stopped and restarted if code keeps running. Browser execution is not a complete security boundary; do not enter secrets or rely on it for untrusted code isolation.

What will this program print?

The two objects use the same class, but each keeps its own title.

class Book:
    pass

book_one = Book()
book_two = Book()
book_one.title = "Dune"
book_two.title = "The Hobbit"
book_one.title = "Dune Messiah"

print(book_one.title)
print(book_two.title)
Choose the output

Practice independently

Mini Challenge — Add a library book

Create a third book object without changing the first two books.

Your goalCreate book_three from Book, give it title and author attributes, and print one sentence about it.

add_book_challenge.py

Optional hints
  • Start with book_three = Book().
  • Use the dot operator to assign title and author before printing.
Ask Sloby for a hint
Sloby, the Python AI Tutor mascot

Your learning mentor

Sign in to ask Sloby

Create a free account or sign in to get AI guidance while you learn.

Sign in to check your understanding

Create a free account or sign in to receive AI feedback and save your learning progress.

Python AI Tutor · Learn by understanding, not just by running code.