1 / 8
Programming · Grade 11 · Chapter 5

Python: OOP Intro

Modeling real-world things as objects in code.

Here's a problem

A Hundred Students, No Structure

Imagine tracking 100 students' names, grades, and attendance using separate lists for each. Adding a new student means updating three different lists in sync. There has to be a cleaner way to represent "a student" as one thing.

Discuss before revealing: What if we could bundle a student's name, grade, and attendance together into a single reusable structure?
Today's tool

Classes and Objects

A class is a blueprint for creating objects. An object bundles related data (attributes) and behavior (methods) together. This is the foundation of object-oriented programming (OOP).

How it looks

A Simple Class

# defining a Student class
class Student:
  def __init__(self, name, grade):
    self.name = name
    self.grade = grade

s1 = Student("Amal", 92)
Let's build it together

Write Your First Class

We'll write a simple class with attributes and a method, live, together.

Activity: Live-code a Student (or similar) class with attributes and a simple method (e.g. a "display info" method). Create a few objects and test them.
Quick check

What is an "attribute" of a class?

AA piece of data stored on an object
BA type of loop
CAn error message
DA comment in the code
Click to reveal answer
Let's discuss

What real-world things could become classes in your capstone project?

Thinking ahead to your Innovation Challenge project — what objects or entities might you need to model as classes?

Before you go

Today we learned...

Classes and objects let us model real-world things cleanly in code. Next week: going deeper into OOP with inheritance!