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

?OOPS in Python? Notes

Uploaded by

Sankeerth Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
40 views

?OOPS in Python? Notes

Uploaded by

Sankeerth Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
OOPS in PYTHON ] CLASS i 4 ciass is @ blueprint for the object. We can think oF class as q sketch of a payyot with labels. It contains all the details about the name, Colours, Size etc. Example ie Class payvor: pass Class Keyword fo define an empty class parvot. 2J-_OBSECT=- An object ( instance ) 1s an {nstentiation oF G Class. When class is defined, Only description fox object is defined, no memory or Stovage fs allocated - Example Class Vehicle $ def__init..(seif, byand,model,type) + Seif. byand = byand Seif. JaS_tank-Size=1& Vehicle object = vehicle C“Honda’, ‘tsuck?) 3j. INHERITANCE %- Trhevitance is a way oF creating Qa nen class fox using detells oF an existing Class without modifying it. Class Parent (): def FivstC Self D3 Print (6 Fivst Function %) Class child (Parent >: def Second CselF >: Pyint C6 Second Puncton’? ) Ob =Chitd C_) Ob. Fiyst ( Ob. Second ( ) Output :-_Flyst Function Second Function 4): ENCAPSULATION 2- Using OOP In python, We can yestsict access 40 Methods and vayiable. This pevent data from divect modification vwihich is called as Encapsulation . Class EmPlovee 3 der__init__ (Seif, name ,Salasy Project): Se\f.name = name SelP.galary = Salary Sele. Prosect = Project def Show (Seif _): Print C'Namet , Seif.name, Salary *,, Sele Salayy > dekwork ‘ SeiF mm Print (Seir.name,* }s working on? , self. Project) 4: Creating object of a class. ae ane ne neh EMP = EmPlonee (*Ram 7s 10,000, ‘Python *) HE Calling Public method CONE SNOW | 2 css tittace ahiaeniincoicaaiaes emer. show C ) emP.work( ) Outpur:- Name : ‘Ram Salary * 10,000 Ram iS working on python. 5d. ABSTRACTION :- Abstyaction is used 40 hide +he internal Functionality eF +he function From the users. Abstvaction can be achieved by using abstract Classes and \ntexFaces- Example!- Print (“Passed value :??, X) Psint (“wie ave inside Absclass task") +est-obj =test. ClassC) x Outper:- We are Inside +eét- class task Te Passed Value : |00 €}. POLYMORPHISM + “Iie IHreval meaning oF pelymosphism is condition Z accuvance $n different forms. Polymorphism Means a use of Single type entity (Method , Opevator,oy Object) +o vePvesent dierevent +upes in different scenayids- Class Rabbit ( )+ def age (Sele ): Print C" determines a3 oF wabbit 77) def colour CSelF ): Print C “determines colour OF yabbit”) Class Horse C Dt derage (self): Pyint (“determines age of horse) def colour (Self Dt Pyint determines Colour of horse”) obj 1 = Rabbit C ObjQ2 = HorseC ) For type In Cob} 1,0b32 2 type.age lL ) type. Colour ) Outpur:- determines age of yabbit. determines Colouy of yabbit. determines age of norse- determines colour of horse- Ste Length of StyIng diet

You might also like