Object-oriented programming
Python supports object-oriented programming (OOP). OOP supports reusability; that is, code that was written earlier can be reused for making large applications, instead of starting from scratch. The term object in OOP refers to a variable or instance of a class, where a class is a template or blueprint of a structure that consists of methods and variables. The variables in the class are called data members, and the methods are called member functions. When instances or objects of a class are made, the objects automatically get access to data members and methods.
Creating a class
The class
statement is used for creating a class. The following is the syntax for creating a class:
class class_name(base_classes): statement(s)
Here, class_name
is an identifier to identify the class. After the class
statement comes the statements that make up the body of the class. The class
body consists of different methods and variables to be defined in that class.
You can make an...