Lesson 35 of 4088%
(Progress persistence is disabled until Phase 9)
Python
Intermediate
Object-Oriented Programming Basics
Understand the core concepts of OOP in Python.
Object-Oriented Programming (OOP) Basics
What You’ll Learn
You’ll learn the fundamental concepts of OOP: Classes and Objects.
What is OOP?
Python is an object-oriented programming language. Almost everything in Python is an object, with its properties and methods. A Class is like an object constructor, or a “blueprint” for creating objects.
Creating a Class
To create a class, use the keyword class.
class Dog:
# A simple property
species = "Canis familiaris"
Creating an Object
Now we can use the class named Dog to create objects (instances):
my_dog = Dog()
print(my_dog.species) # Canis familiaris
Why OOP?
OOP allows you to model real-world concepts in your code. Instead of having separate variables for a dog’s name, breed, and age, you can bundle all that data together into a single Dog object. We’ll explore this more in the next lesson!