0 ratings0% found this document useful (0 votes) 10 views8 pagesOOP Python
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
Oops 5
. ¢ :
ebject oviented prrogwannnnna
‘ z
uses object & classes E
> aims
to Twplement veal world q
entities ike inhesdtane, polymor pis
> entapaulation , ebc-
binds data -§ functiomn a8 Single unit
L
abtrioutes
7
methods
b + Class 4 + Collection of objech
» Contain’ blue point / prototype
From which
Objet ave created:
Creation of class) Created by "class" Keyword.
jf] class A:
Pass
object j » Instance. of class
2 Contain,
and
teatng objec j
i) obj= A( )
State / Attstbuke
behaviour,
(& scanned with OKEN Scannerclass A
¥=5
dee B __tit--(selP, Zz): |
selFe z= Zz :
SelfeM = tH SAr.X
deg Bl selt).:
yeturn Hello” 4. Self-z
x
clay 1S Created Now Lh Creale
4 © Obyeck
= AC" Harsha")
psint ( As z) a?
Print Cp Bl )) —> Hello Harsha
privt ( pexX) —> 5
peat CpeM) —> 5
° Iw above code 5
tel ts Sumilan to a Gnstructl
iw OCPP Tris a method that is
L, executed when a Class is ‘wae
ivitiated » B ¥S a Method that
fs executed volen we Call But
cawit--C ) ts execated amt malt Cally
dusing object cveokion-
Harsha
(& scanned with OKEN Scannerextva parameter used in
every — method j
Wustance of class (-veference to
: Curvent tustance of the claw)
used ) to aciess variables belong
to the clay
Wwe Can name any ling fuglawe
Ow
exbya paramere ir every
oh. SelB bub ioe musk uce |
Methoa
SelP eZ & Selfe Mone attributes
oF © L_imibe-C) Meirody — volach
ALCS Joriables fyewe: Clark
and -~Wit--C) method
\
* LL sty.0) ~» “Futon sea, ftp
_ veburn Content yohen
Cla% object fs Yepresewted
a — stxing.
EXD pe AO)
Pot CP) > Crna A objet at OnIsHe
(& scanned with OKEN Scannerovo ustng Se Ant Jib
clay AY
clef F _eiy_ -CSEIEDE
yetumm ' Hello!
Now pant (p) >" Hello"
we Com Modify object’ Proper tics ;
peX = 25:
we Caw Delete Object Prmpertics,
eee
Th we pan delete Objects also
Imhesitanle § obtaining All method &
| pHOpesticss Prom anvther Chis.
bp Pavent | base class: (lass being imhented
cw ld / desived class. class that inhenits -
Ex) ‘eta@isc) Ads!"
def in| selP 5 ab) :
selPeQ=a'’
{ Selk-b =b
typo de B (sefey: 1?
1 pate C Selt-ay Self)
(& scanned with OKEN Scanner= Creaking Cla clos +o A;
class cH{A) ;
pow
X= CH( " Harsha", 48)
X* Bl ) > Harshn 49
CH - inhesited __init_- & 8
frm claw A
Tf we aaa —init--() to CH,
FE will not use _—anit_- 0) of
clays A.
Ne Chile's init. Oveyaides ..
inhevitame of Parent's
“4
Pa A EB
° We Con also Use
—-mit---
chi ng : pPorenb
Exs
clam CHCA):
| def ~-init- (self) asbe) +
a Ae —-init — (SAP abl
(& scanned with OKEN Scannerx= CHC” hoosha’ ag, , Ce)
x- BC ) ~~ Haysha 48
m, eee fs rot used in B:
cupes ( js funttion that makes child class
inherit at meltrods E propestien
ey deP _ _ it) -- Gel)
super().. -mit--( Sf arb)
COR Te
2 along vith inhesited methods é propesties
we cn also Create /add New
methods 0, Child class:
cane
polymorphism ; methods / operation tors /
y Ny Functions ,
hoy Loswn With Same
name g CON be executed
on many objech / class.
ey ien() > used to fivd bength OF Lict
7Staing
J tule, set, Dictionony.
(& scanned with OKEN Scannere More than one Closs can have
Same Method name
and the Methods WOTK pith
yesped +o the objecd -
ex,
7 Clam A
dep —-init— (celf;a) +
Self aa
def B (self):
paint (' Hi")
cla% D> ‘
def --wit_ Ccelf,d) . |
Self -d cd |
def B (self ) q
. Pant (4 Bye'') Fe 7
dae ee oe
Y= ple Haysha’‘) j
xB() —>4At |
BC) —> Bye
(& scanned with OKEN Scannerethod Over loadin 5 % or Maye Method
with Sawe but different wo- oF
Pavamect oo Bt dittevent type
of foramete gt oth = ave. Called
ovey loaded methods & Wis is (alled
meWod over loadivg.,
x def A ( ab): 4 def A(aio/¢):
Sum = a+b
Sums oxb+e
vetutn Sum
yerumn Sum:
Python Does Not Suppor Method
Overloading . .
so we Can define many Methods put
We Can use the later Method:
poly mor Prism § lwhestonce;
Metnads OF Child Clas
parert claw methods
Nowe
Overnides
wilh Samo.
(& scanned with OKEN Scanner