Today we will be looking at the object orientation concepts available in Python. Python is an object-oriented language and offers much functionality that would be expected to come with such status. You can write classes, instantiate objects and inherit from other classes etc.
Let’s start by declaring a class, this is done as so:

Then we’ll need to write the constructor. In Python, this is a little different to any languages we’ve seen previously:

The “init()” function acts as the constructor, and note how it has been passed “self”. Ths is used to represent an instance of a class, so that the class knows which object it is operating on. This is different to something like Java, where you only need to use the “this” keyword to remove ambiguity from the code.
It is important to bear in mind that most functions you write in Python will require “self” to be an argument.
When it comes to actually instantiating an object of the class, interestingly enough, we don’t have to pass “self” to the function. We just declare the object name, assign it the constructor with the required arguments, as seen below:

This means you only have to worry about “self” when it comes to writing the actual classes, and not when you’re using the classes in your code.
Lastly, we’ll be looking at “duck typing”, which is a type system whereby the type of the object is less important than the method it defines. This means that when the Python code is compiled, instead of checking for types, they check for the method or attribute the object is using.
This means that you can have a list of objects displaying their name attribute, and as long as each type of object in that list has this attribute in its class definition everything will be okay. This is shown below:

Then, if the object doesn’t have the method, an error will occur.
Next time
That’s if for this time, next time we will be looking at mathematical functions, pure functions, anonymous functions and functional operations. In short; a whole lotta functions!