Classes and objects
Classes are fundamental to OOP languages such as Python. A class is simply a template for creating objects. Classes define an object’s various properties and specify the things you can do with that object. So far in this book, you have been relying on classes defined in the Python standard library or built into the Python programming language itself. For example, in Exercise 38 – finding the system date of Chapter 3, Executing Python – Programs, Algorithms, and Functions, you used the datetime
class to retrieve the current date. You will start off by exploring some more of the classes you’ve already been using. This can be performed in a Python shell or Jupyter notebook.
Create a new integer object called x
in a Python console:
>>> x = 10
>>> x
10
You can see the class that x
was created from by calling the type
function:
>>> type(x)
<class 'int'>
The integer
class doesn’...