Elena' s AI Blog

Python classes and pigeons

01 Sep 2022 (updated: 14 Sep 2026) / 25 minutes to read

Elena Daehnhardt

Three white doves, Jasper AI-generated art, January 2023


TL;DR:
  • Use Python classes for OOP: inheritance reuses code, polymorphism allows different behaviors, encapsulation protects data. Define classes with __init__, methods—essential for organized code.

Previous: Part 4 — Python's Standard Library: Your Built-in Toolkit

Next: Part 6 — Python Generators and Iterators: Lazy Birds

Happy 1st of September!

I have decided to write a letter to you and share some thoughts and gratitude for your visits.

I recently walked into my favorite park and saw beautiful white pigeons picking some worms. They were mingling without any concern with other “usual” pigeons. They looked so different but were also quite indifferent to their differences from each other. At the same time, they were pigeons who did not care about feather color differences. They all enjoyed green grass and little worms in it.

Birds are so beautiful, all of them. And I have decided to do a simple wrap-up of simple Python classes defining birds and pigeons. I think that this post is a good recap or start for understanding Object-Oriented Programming and the available functionality in Python.

Table of Contents

Object-Oriented Programming (OOP) in Python

Object-Oriented Programming (OOP) is a programming paradigm that organises code around objects — bundles of data (attributes) and behaviour (methods) defined by classes. In Python, OOP lets you model any real-life or abstract entity as a reusable class and create many independent instances from it.

There are several programming paradigms in computer science, and writing code is the best way to actually understand them. This post focuses on Object-Oriented Programming: as the name suggests, we deal with objects, describing real-life or abstract things with classes.

For instance, birds. We can define a class for birds and also define a class for pigeons. Both classes will be similar, right? And with Python and OOP we can describe birds and pigeons very neatly and create many instances of both classes, thus creating many bird objects defined by both classes!

Defining Classes in Python with init

🔒 Subscribe to keep reading.

Class Methods in Python: Defining Object Behaviour

🔒 Subscribe to keep reading.

Inheritance in Python: Reusing a Parent Class

🔒 Subscribe to keep reading.

Polymorphism in Python: Overriding Inherited Methods

🔒 Subscribe to keep reading.

Encapsulation in Python: Protected and Private Variables

🔒 Subscribe to keep reading.

Conclusion: Python OOP Concepts Summary

🔒 Subscribe to keep reading.

References

🔒 Subscribe to keep reading.

You've hit a Deep Dive tutorial.

I spend dozens of hours researching, coding, and breaking things to write these guides. This content is free, but reserved for my subscriber community. Drop your email below to unlock this guide (and all past/future deep dives):

Already a subscriber? Use the magic link from your last newsletter, or reset your password.

New subscribers get an inbox mail: Set a password to unlock articles. The form does not log you in — use the same email afterwards.

desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.

Citation
Elena Daehnhardt. (2022) 'Python classes and pigeons', daehnhardt.com, 01 September 2022. Available at: https://daehnhardt.com/blog/2022/09/01/coding-python-classes-oop-polymorphism-encapsulation-inheritance/
All Posts