Lesson 01
OOP Roadmap — Classes, Objects, and the Seven Principles
See the Python OOP roadmap: classes, objects, constructors, encapsulation, inheritance, and polymorphism, and why every value is an object.
Python can be written as a list of steps, and it can be written as objects. This page is the map. The next lessons walk the map one idea at a time.
Use the playground at the bottom of this page, then take the quiz.
What you will learn
- How procedure-style code differs from object-style code
- Why Python is described as both
- The seven object-oriented principles
- The order you will meet them in this module
The picture
Industry languages tend to follow one of two styles.
| Style | What you organize | Examples |
|---|---|---|
| Procedure / functional | Steps and functions | C, and the Python you have written so far |
| Object-oriented | Data plus the operations that belong with that data | C++, Java, and Python classes |
Python is in both lists. You can still write functions. Inside the language, values such as 12 and "Avery" are objects too.
Five practical reasons this style exists:
- An object can hold many related fields together.
- That bundle can be passed around as one value.
- Fields you want to keep private can sit inside the object.
- The data stays next to the methods that use it.
- A new class can reuse an existing class instead of copying it.
Message passing is the seventh principle. It means calling a method on an object, which you already do when you call a function. The Functions module covered calls. This module gives those calls a class to live in.
The learning path below is the order of the lessons. Constructors and destructors sit inside the class story. They are not extra principles.
Example
class Badge:
def __init__(self, m):
self.label = m
badge = Badge("Avery Lane")
print(type(12))
print(type(badge))
print(badge.label)type(12) and type(badge) are both types of objects. The class is the plan. badge is one real instance holding the label Avery Lane. Change the label in the playground and run it again.
Key takeaways
-
Python supports both functions and classes
-
A class is the blueprint; an object is the memory
-
The seven principles are classes, objects, encapsulation, abstraction, inheritance, polymorphism, and message passing
-
Constructors and destructors are part of the class path
-
Next: Classes — why a class is a programmer-defined type
-
Previous: OS Operations
Loading playground…
Check your understanding
OOP roadmap quiz
Python belongs to which style?
1 / 10