OOPs Concept in Python

 Python is also an object oriented programming language. We can develop application using Object-Oriented approach.

In OOPs major features are given below:

  1.  Class
  2. Object
  3. Method
  4. Inheritance
  5. Polymorphism
  6. Data Abstraction
  7. Encapsulation

Class in Python:

Class is a blueprint or protoype from which object are created. It is user-defined type. Class in python basically bind the data(variable and functions).

For exmaple : Suppose a class is a prototype of a building. A building contains all the details about the floor, rooms, doors, windows, etc. we can make as many buildings as we want, based on these details. Hence, the building can be seen as a class, and we can create as many objects of this class.

How to Define Class in Python:

In Python Class is defined by the keyword class. Syntax Given Below:


Syntax:

class MyClass:

     #statement_Suite

In Python, each class is associated with a documentation string which can be accessed by using <class-name>.__doc__. A class contains a statement suite including fields, constructor, function, etc. definition.

Example:

class msg:
def display():
print("Hello WOrld")


Python Objects:

An Object is an instance of a Class. After a class has been established, you may make objects based on it. By using the class constructor, you may create an object of a class in Python. The object's attributes are initialised in the constructor, which is a special procedure with the name __init__.


Comments

Popular Posts