Using object-oriented programming
OOP is a way to structure data into objects. The Python program is an object-oriented program in that it structures algorithms as objects in order to bundle them based on properties and behaviors. To learn about OOP, we will need to know how to do the following:
- Create classes
- Use classes to create objects
- Use class inheritance to model systems
In Python, we use classes to bundle data. To understand classes, let's create one:
>>> class Books: pass
We can then call the Books()
class and get the location where the class is saved on our computer. Notice that my output will not match yours, as the class will be saved in different locations:
>>> Books()
This is my output:
<__main__.Books object at 0x000001DD27E09DD8>
Now that we've created the class, we can add book objects to the class:
>>> a = Books() >>> b = Books()
Each of these instances is a distinct...