Exercise 45

Basic Object-Oriented Programming

In Exercise 44 you learned how to use a function to create special dict containers with functions attached to them. In this exercise you’ll learn the “right” way to do the same thing using Python’s class keyword and the object-oriented programming (OOP) features.

OOP is very complicated to understand and explain, so we’ll focus on code to start and slowly build up your understanding of the concept. The most important thing for you to remember when studying this is that OOP is weird. Humans don’t think about the world like this, and most of the theory behind OOP has been debunked by modern psychology and neurology. This means you need to keep grinding OOP code until you get it. It just takes time ...

Get Learn Python the Hard Way: A Deceptively Simple Introduction to the Terrifyingly Beautiful World of Computers and Data Science, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.