Python OOP – Classes, Methods, Attribures, Composition, Inheritance

Have you ever dreamt about coding classes like a pro? No? You had “normal” dreams? Anyway, in the video below, I am solving 3 exercises with a lot of debugging and some basic tests. Exercises are from the book Python Workout and I am using Jupyter Notebook as IDE.

The code in GitHub is here.  In general, these are the exercises:

Exercise 43:

The interesting “thing” here is the inheritance of class Animal towards class Wolf. Additionally, this one – self.__class__.__name__.lower() saves some lines in the “Big Picture”. Using the __init__ method of Animal through the children’s classes, is also a good example.

Exercise 44:

This is a rather easy one (although I have debugged it for quite a lot of time in the video). “Composition” is the key word for this exercise – having an object, that contains other objects can be interesting and of use.

Exercise 45:

This one is the last exercise, that is actually carried out. The functions for filtering objects, by their attributes and the sum of another attribute is actually an interesting one. Talking about animals_by_legs() and number_of_legs() .


Tagged with: , , , , , , ,