Python Object Oriented Programming

In this Page, We are Providing Python Programming – Object Oriented Programming. Students can visit for more Detail and Explanation of Python Handwritten Notes Pdf.

Python Programming – Object Oriented Programming

Object-oriented programming (OOP) is a programming paradigm that represents concepts as “objects”, that have attributes that describe the object in the form of data attributes and associated procedures known as methods. As mentioned in chapter 1, Python is an OOP language. In Python, class form the basis of OOP. Some of the features of OOP language are:

  • Inheritance
  • Polymorphism
  • Encapsulation

Some of the advantages of the OOP approach are:

– Reusability: A part of a code can be reused for accommodating new functionalities with little or no changes.
– Maintenance: If some modification is made in the base class, the effect gets reflected automatically into the derived class, thus, the code maintenance is significantly less hectic.
– Faster output: With organized and methodical coding, there is little room for error, and as a result programmer can work comfortably, resulting in fast and efficient output.

Method object

In the MyClass example, x. f is a method object and x. f ( ) returns the string ‘hello world’. The call x. f ( ) is exactly equivalent to MyClass . f (x). In general, calling a method with a list of n arguments is equivalent to calling the corresponding function with an argument list that is created by inserting the method’s object before the first argument

>>> x . f ( )
' hello world '
>>> x . f ( )==MyClass . f ( x )

The method object can be stored and can be called later.

>>> xf=x . f 
>>> print xf ( )
hello world
>>> type ( xf )
<type ' instancemethod ' >

Python Programming OOP