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

Python Complete Notes - pdf-18

PYTHON OOP

Uploaded by

anupamakarupiah
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)
64 views

Python Complete Notes - pdf-18

PYTHON OOP

Uploaded by

anupamakarupiah
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
~ —— bound! to the My have the acerss fo the stake of fakes a” class patameber that ol he obfect . inghance. ba. It con modify a class state that would apply QHoss allt HH instances of the class. for ¢ i lo t gs tk can Modify a class vasi‘able that will be __applicable all _Hhe fnstances. 9” “ the class a it inks to the class and — i Statfe_method doen't steerive an implicit feat argument I Syntax - class { (object): ‘ ' @statfemethod f det fun (augl, Ougd,--): v T “ 1 : ‘ Atturns : a stale method for funcHon fun * A_stalfe_mtthod: fi alte @ method that fs bound t the class and nok the object of the clase, 0 “ A_statle method can't access ov modity the class state, It ts patsent ina class because fk makes Sense fo the method © bo be paesenk in class, & = Class method vs state method - Qe tA lass method fakes ds ar the fist paxameley while a [- Stale_method needs no _specitfe payametous . s 2. A lass tntthod can access or modify the dass state - while state method can't aeeeas bp modify tt, itd In general, slatte methods know nothing about” the dass oS state. che oe atl Hype methods Mat take some s. Sorat SS aS ~ Date -seecsseseceee auamehtas: and work upon those payamekou. On the iw hand class methods must have class asia parameter. » 5 “ye _Inhoutance = Th ts the capabtitty of one class. fo ‘dorive- or ~Jfaheatt the puoperties fom another class, we Advantages - Bs 7 tt rer ned - world 2eationshia well: ii provides acusuabifhy. of a code. We don't have to SF wile the Same code again and vagain. Also, Tk allows ~¥_us fo add_more features Yo a. clais “without « modifying Bt t ! STH is transitive in. nature, which means: that tp class 8 TF tnheatts fom anothen Class Ay then all the subclasses 2 of 6 would automatically: inhuitt pom class AL = class Penson (object) s = # Consbiuctor 2 def-fntt- (sel, name): 2 self name i= name # To get name a) ady getName (self); & vieruyn selfs name # To check. if :this person tgian employee defi fsEmployce: (self): “aeluyn False Gs Zt Inherited ov Subclass class Empleo: te (Parton): de Hee we elurn biue det _tsEmployee (self) + ; sieluyn. True Employee) pence OP - “geek, False) a aceame Ci 4rek ay Tue) : te Og : nig 6044 & = What ts object class 9 i : ike Jove object class, in python oe objeck fsa Hook 2 of oll classes. Example ~ class subclars name (superclass name): pop class | Peuson (object): def-init_ (self) name, idnumbey):: Stlt mame = name 4 Self. fd numbew 2 idnumbey deb display (self): pyint Tosetp. name) | stint (self. idnumbe) # child class class Employee Person): def —tntt_ iagieenet tdnumber, salar Self. satosy = salany i self. oat = _post —e = inthe (ait name, idnumbey = a= Employee (* Rahul’, 885380000, “Inke da, display © gs! APN HH bla ble hola A Date orms_ of Inhow ingle. Inheritance - When Oo child Ton one pount class, ih fs oe nee. 92 Multiple multiple inneuttance 5, class Basel (obpect) + ys: def -fntke (self): i‘ Self. shal = “Geek” Se paint (“Gasel’) Tass Base? (object): def int. (self) + Selp. shad = “Geeka” print ("Base 2") class Derived (Basel, Base 2): def —fnit— (self): # Calling constuuctor of Basel and Gase2 classes Gasel ._ tnit_ (self) Based. intk- (self) paint (Devtved") act pint Sts self): pint (self. shil, self. shay 2) ob: Deitved () ob: paint Stis () Te Inheritance - When a child class inhusits trom paxent classea, it ts called multiple ; 1 + SIP - Base! Base | Based as Base 2 borived barved Geek | Geek 2

You might also like