From objects to behaviors with OOP using Python
How to manage complex programs with a bunch of data to manipulate, and a bunch of things to do?

There is a bunch of possibilities for how you can structure a program, and if we combine these possibilities together in sets of structured rules and properties, we get to what is known as a Programming paradigm.
Object-Oriented Programming (OOP) is nothing more than a common programming paradigm, meaning, a way to design software. It is supposed to facilitate the design of large software projects and it is widely used across academia and industry.
In this article, I want to discuss the basics of OOP using Python.
From Complex Components to Intuitive Objects
OOP is supposed to be a programming paradigm that makes the Software Development process feel more intuitive. Why? Because we get to think about complex components in terms of objects and their relationships.
An object is an entity, or "thing", usually a noun of some sort like a person or a motorcycle.
Each object has properties like a person has a name, age, and (maybe an address), a motorcycle has a color, a model, and a license plate.

Beyond properties, individual objects also have behaviors, like a person walks and talks, while a motorcycle, can turn on and off, run at given speeds, etc.

There are other complexities we are not mentioning here like, what it takes to be an object? That seems kind of subjective right? Also, once something is an object, what are the rules for something to be a property or behavior?
We’ll skip the questions for which clear answers are not available and stick to the idea of things as objects with properties and behaviors.

Python Classes
To get into the topic of objects, properties, and behaviors, let’s use Python classes as our guide. There are a few things to think about when discussing Python classes:
- Classes are things we use in Python to create objects
- We can create as many unique objects from a single class as we want
- Classes define something called a
type
in Python - Instantiation is the name of the process for creating an object from a class in Python
Let’s unpack all of these affirmations with a simple example:
name = 'Lucas'
Here I am simply creating a variable called name
with a value Lucas
, this variable is a reference to an object, in this case, the type
of the object is a str
because to create it we instantiated the Python built-in str
class.
Now, let’s create a class called Person()
, and another one called Motorcyle()
, which will have respectively the properties (attributes): name
and model
.
class Person:
def __init__(self, name):
self.name = name
class Motorcycle:
def __init__(self, model):
self.model = model
p = Person("Lucas")
print(p.name)
m = Motorcycle("Scooter X3000")
print(m.model)
Lucas
X3000
In this case, we created the Person()
and Motorcycle()
classes which have their names and model properties respectively, then we instantiated them, which means we created unique objects out of these classes (or types), in this case with the name "Lucas"
and the model "Scooter X3000"
.
We did that using what are known as constructors: __init__
, methods used in Python to initialize data, these are methods called when we instantiate classes.
In the context of Python Classes, the self.name = name
line is an example of an instance attribute in Python, which refers to the specific attributes of a unique instantiation of that class.
We can create as many instantiations of these classes as we want:
# instantiate 3 people and 3 motorcycles
p1 = Person("Lucas")
p2 = Person("Beatriz")
p3 = Person("Sara")
m1 = Motorcycle("Scooter X3000")
m2 = Motorcycle("Scooter X4000")
m3 = Motorcycle("Scooter X5000")
# and so on and so forth
One way to think about this is that the class is the template, and each instantiation, is a real example application of that template.

Consider this analogy with a grain of salt given that it might be confused with abstractions and a specific type of Python class known as Abstract classes.
How about behaviors?
We can add functionalities to our Python Classes by adding methods that allow them to do things, for example, our Person()
class could have a walk()
method and our Motorcyle()
class could have a turn_on()
method.
class Person:
def __init__(self, name):
self.name = name
def walk(self):
print(f"{self.name} is walking")
class Motorcycle:
def __init__(self, model):
self.model = model
def turn_on(self):
print("Motor is on")
p = Person("Lucas")
p.walk()
m = Motorcycle("Scooter X3000")
m.turn_on()
Lucas is walking
Motor is on
But, how can classes talk to each other?
Let’s say I wanted to have my Person()
class to be able to relate somehow to the Motorcycle()
class, how about we write a modification to the turn_on()
method from the Motorcycle()
class, where it requires an instance of the Person()
class to be created?
class Person:
def __init__(self, name):
self.name = name
def walk(self):
print(f"{self.name} is walking")
class Motorcycle:
def __init__(self, model):
self.model = model
def turn_on(self, owner):
p = Person(owner)
print(f"{p.name} turned the motor on")
mt = Motorcycle("Scooter X3000")
mt.turn_on("Lucas")
Lucas turned the motor on
Now, we start to see properties, behaviors come together with class interactions. This is the start of the world of OOP, as objects start interacting with each other to create complex dynamics.

Object-Oriented Programming is a Skill
OOP is a fascinating subject. How can we bring objects together to create interesting software dynamics? The answer is probably not very clear given the complexity of the question.
But it makes sense to think about it as we evolve as Python developers. Thinking about software components as objects that we can create and bring together to generate rich interactions that culminate in interesting features is a lifelong skill, one that is deeply appreciated in well-written software across academia and industry.
If you liked this post, join Medium, follow, subscribe to my newsletter. Also, subscribe to my Youtube channel connect with me on Tiktok, Twitter, LinkedIn, Instagram! Thanks and see you next time! 🙂
If you want to get into object-oriented programming, check out this book:
This is an affiliate link, if you buy the product I get a small commission, cheers! 🙂