Classes and objects
A class is a logical grouping of variables and functions. The class keyword is used in Python to define such logical groupings. A class often represents a real-life entity, for example, book, author, publishers, and so on. Entities have properties, which are represented by the variables defined in a class. Functions in a class, often referred to as methods, define how data about an instance of the entity can be captured and transformed. An instance of a class is a single realization of the entity. For example, book is an entity whereas Practical Time Series Analysis is an instance of book. To create instances, we initiate an object of a class. Object definition involves assigning values to the variables of the class through the constructor function. This job is done by the __init__
method that takes input and assigns them to class variables. The __init__
method can internally call other functions based on the logic of creating the object. Let's define a class about books...