Python - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Python OOPS

Python OOPS

shape Description

The Object Oriented Programming language is a programming dialect display sorted out around an objects instead of "activities" and information as opposed to rationale. Truly, a program has been seen as a legitimate methodology that takes input information, forms it, produces yield information. The initial phase in OOP is to recognize objects of the software engineer needs to control and how those identify with each other, a practice regularly known as information displaying. Once a protest has been distinguished, it is summed up as a class of objects which characterizes the sort of information it contains and any rationale successions that can control it. The following are the OOPS concepts.

Object

shape Description

Object is an element that has state and conduct. It might be anything. It might be physical and sensible. In Python everything is an object. All functions have an implicit quality __doc__, which gives back the doc string characterized in the source code of the function.

Class

shape Description

Class can be characterized as an accumulation of objects. It is a consistent substance that has some particular methods and attributes. The following is the syntax. [c]class ClassName: <statement-1> . . . <statement-N> [/c] The following is an example for the classes and examples. [c]class BankAccount: def __init__(self): self.balance = 0 def withdraw(self, amount): self.balance -= amount return self.balance def deposit(self, amount): self.balance += amount return self.balance >>> a = BankAccount() >>> b = BankAccount() >>> a.deposit(100) 100 >>> b.deposit(50) 50 >>> b.withdraw(10) 40 >>> a.withdraw(10) 90[/c]

Method

shape Description

Method is nothing but a function that will be connected with an instance. In Python, the method is not one of a kind to class occasions. Any object sort can have the methods. The following is an example. [c]class Parent: def myMethod(self): print 'Calling parent method' class Child(Parent): def myMethod(self): print 'Calling child method' c = Child() c.myMethod() [/c] Now compile the code result will be as follows. [c]Calling child method[/c]

Inheritance

shape Description

An inheritence determines that object gets every one of the properties and practices of parent question. By utilizing the inheritance, one can characterize another class with a small changes to the current class. The new class is known as child class and from which it acquires the properties is called parent class. It gives re-convenience of the code. The following is an example. [c]class A: def f(self): return self.g() def g(self): return 'A' class B(A): def g(self): return 'B' a = A() b = B() print a.f(), b.f() print a.g(), b.g()[/c] Now compile the code result will be as follows. [c] A B A B[/c]

Polymorphism

shape Description

Polymorphism is made by two words poly and morphs. Poly implies numerous and Morphs implies frame, shape. It characterizes that one errand can be performed in various ways.

Data Abstraction

shape Description

Data abstraction and encapsulation both are frequently utilized as equivalent words. Both are about equivalent word since information deliberation is accomplished through embodiment. Abstraction is utilized to cover up interior points of interest and show just functionalities. Abstracting something intends to offer names to things, so that the name catches the center of what a capacity or an entire program does. The following is an example. [c]class splesson: __secretCount = 0 def count(self): self.__secretCount += 1 print self.__secretCount counter = splesson() counter.count() counter.count() print counter.__secretCount[/c]

Encapsulation

shape Description

Encapsulation is additionally the element of protest situated programming. It is utilized to limit access to strategies and factors. In exemplification, code and information are wrapped together inside a solitary unit from being adjusted coincidentally.

Summary

shape Key Points

  • The C language is procedure oriented language.
  • The OOPS concepts provides hiding concept to provide security.
  • The calculator is the best example for the polymorphism.