CH - 9 Object Oriented Programming
Concepts of classes, objects, inheritance, and polymorphism
- Python is also an object-oriented programming (OOP) language and everything in python is an object. OOP is a programming paradigm that revolves around the concept of objects, which represent real world entities. Each object is created from a class, which is like a blueprint that defines its properties and behavior.
- Classes: A class defines the structure of an object. It includes attributes (data) and methods (functions) that define what the object can do. For example, in a program that simulates a library, you could have a class called `Book` that stores information about a book’s title, author, and ISBN number.
- Objects: An object is an instance of a class. You can create many objects from the same class, each with its own set of attributes.
Inheritance: This is a feature of OOP that allows one class to inherit the properties and methods of another class. It promotes code reusability, as you can create new classes that extend the functionality of existing ones. For example, if you have a `Vehicle` class, you could create a `Car` class that inherits from `Vehicle` but adds more specific attributes, like the number of doors or the fuel type.