Object oriented programming- In this program step-by-step instructions are written in a logical order. In OOPs, we divide the things into objects.
Essential features of object oriented programming are:-
- Data Encapsulation
- Inheritance
- Overriding
- Polymorphism
A class is one of the basic building blocks in python. It is also a core concepts in a style of programming known as objects oriented programming.
OOP provides an approach to structuring programs/applications so that the data held, and the operations performed on that data, are bundled together into classes and accessed via groups.
Classes are blueprint of the objects. You can think of class as a general idea of a category of an object.
Syntax:-
class class_name: ''' class functions''' statement1 statement2
e.g.,
Class person: name='Ravi' gender='male' def showinfo(self): print('name', self.name) print('gender', self.gender) a=person() a.showinfo()
Output- name Ravi gender male
An object is simply a collection of data (variables) and methods (functions) that act on those data. Similarly, a class is a blueprint for that object.
An Object is an instance of a Class.
An object consists of :
- State: It represents the properties of an object.
- Behavior: It reflects the response of an object to other objects.
- Identity: It gives a unique name to an object and enables one object to interact with other objects.
This is all about class and object in python.