0% found this document useful (0 votes)
2 views

python notes

The document provides an overview of Object-Oriented Programming (OOP) concepts in Python, including classes, objects, inheritance, encapsulation, abstraction, and polymorphism. It explains each concept with examples, demonstrating how to define classes, create objects, and utilize methods. The document emphasizes the importance of these principles in structuring and organizing code effectively.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
2 views

python notes

The document provides an overview of Object-Oriented Programming (OOP) concepts in Python, including classes, objects, inheritance, encapsulation, abstraction, and polymorphism. It explains each concept with examples, demonstrating how to define classes, create objects, and utilize methods. The document emphasizes the importance of these principles in structuring and organizing code effectively.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
OOPS in PYTHON i). CLASS *- A class 1$ a blueprint for the object. We can think of class as q sketch of a pavvot with labels. Tt contains all the details about the name, colours, size etc. Example :- Class parwor : ass Class Keyword fo define an empty class paryot. I; OBJECT An onject( instance ) 1s an instontiation oF O class. When class ts defined, Only descriPtion fox object is defined, no memowy or Stovage is allocated - Example :- Class Vehicles def__init. (selfs byand, model, type ) Seif. byand = brand Seif. type = type Seif. 998 tank-Size = 14 Nehicle_ object = Vehicle C*Honda’, Struck”) 3), INHERITANCE 3- Thhevttance js a way oF creating a new class for using detetls of an existing Class wilthout modifying tt. Class Parent (): Print (6 Fist Function *) Class child(Pavent >: det Second(seiF >: Print Cf Second function’ ) Ob =Child C_) Ob. Flyst ( Ob. Second ( ) Output :-_Flyst Function “Setond-punction re 4J- ENCAPSULATION % Ucing oof in python, We can yestsict access 40 Methods and variable. THIS pyevent data from divect Modification which is called as Encapsulation. Class EmMPIOYEE : def__init__ (Seif, name ,Salasy » Prosect ): Seif. name =name Sei. salary = Salary Sek. Prosect = Project def Show (Seif J? Print ‘Name? , Seif.name, ‘Salary’, , Sele Salary) defwork (SelF) ? Print (Seif. name, * ts wosking On? , Seif. ProSect) # Creating object oF a class. emP = EmPlonee(*Ram ?, 10,000, *Python * ) He Calling Public method . empP. show () emp. work ) Output: Name : Ram Salary * 10,000 Ram is working ©n python. DJ. ABSTRACTION Abstyaction is Used 40 hide the intemal Functlonatity oF the function from +he users. Abstyaction can be achieved by using abstyact Classes and interfaces: Example:- Eyom abc Import ABC , abstractmethod Class Absclass (ABC): ef Print (Self x): Print (“Passed value :”? , X) Print (“we are inside test_ Class task”?) Outper:- We are Inside test. class tasic uae Passed Value :|00 8). PolYMoRPHISM 3 The \tteval meaning of polymosphism 3s condition & occurance In different forms. Polymosphism Means a Use oF Single type entity (method , Operator, oy Object) +o vepresent alFerent types in different scenaylos. Class Rabbit (_)+ def a9e (Self ): PrintC determines age of vabbit *?) def Colour CSelF ): Print C“detewmines colour oF yabbit") class Horse ( J: defage (self): Print “determines age of horse) def Colour (Self ): Print C determines Colour oF horse”) Obj 1 = Rabbit C ) ObjQ = rorseC ) For type in (obj 1,0b)2 )? tyee.age C ) type. Colour ) Getermines age oF yabbit. determines Colour of yabbit. determines age of horse. determines colour of horse. Sty Length of sting Ten) List lumber OF Items diet Number of Keys

You might also like