Python Handwritten Notes
Python Handwritten Notes
Note
By – Samim Aktar
R. object orjeoled boqyowming
Concept of oop:
>’ cop is noking bat tie obect oaened
>Tws mainy
tocuses on pgyamig
72usable code- DXY con cept.
>O0p maKes the program eay to ondextavd az well nel| 4 fet.
class;
AclaAs is a blue paivt o the
class Bak: olject.
pass
obect:
An oljecf as
Instonce is an insntiation. of a dass
>Here varjale s ae alled
metkods, aribudes and fnctons
2-iit_method:
’ Atbibues are
defined in
the frst method to oum 9 SOonkisa2method of he alass and t is
cleds BGnk Aceount(J; the objeet is cseated.
defint. (self nome, balance) :
self.balance balan ce
s Creatvg okiect self. mame =mame
Useo 1= BamkAccount Samiwn'
Vses22 lo606)
Methods
Bam-Aca0unt
aka tuefons:
(A Rtor', 5000)
balance)ealonce:
Dnheatance:
Snheitance is oay of creain memew elass b
the defails of
othex elass withoat
class Bann AeUnt :
def--tt (self, mome, balance):
self. balance mbalamcelass
Sef. nome = Mame ChiBanAccooteank
Aceoont):
defpost (Gelf. amoun):
sef. balonce + balmceeif amoont <= I000:
def witidow(self, am00nt): self. balanee
-= Qmoun
self. balance Qmount else
print( con not
paint'Available balance :
self, balan ee)
Csde
# paret class
class Bamk-A ccoont :
dof -- nit- (selt, mame,
self.mame. -=Mame balance) :
self. balance = balance
def deposit(ey,emouni):
Self. balon ce += aane anoun
def nitdasosdf, amount):
def--iit(self):
Sef. -mupice =900
def sel (se):
def cetMakice (sef pice):
setf mtprice pice
= 0Sa seter fonchon
Csell 0 e. setMonfice( tor)
C. Sell (U
#toy to clang tle price
e. selt l)
# Polymoaphism :
’he iond fehynoxphism means haw
color
pint ("
(" thisfunfion dele~ nines the colbr of tose.")
psint(ar)
pint (aar)
2: Ce.2x3 45]
point (am)
pont 'nombes of simenicon :', G8. ndin)
(ttC 123 J]J] pint (omttpr)
numbes of dimen son :4
np.arey CC2,3,45
pönt{'2rd dement o 1t din:', m prntLast elemet fom
2hd elenent on 19t din:7t 2nd dim: ', am-2
Lastelemert fom 2nd din:to
O# slicing staot: end: ste
print (at
print a
point (Y)
pint (at)
Pondaa
>fondes is the Pythoni libraay vsed-to anayze he
sesies: Apaudaa sexies is ike acoun inn atable.
a
data.
g+ is me-dimentionl amay haldug,data gf an) e.
a Dalafone: Apavdo, batafiame is a zdimen sional da sucre
ike a2-cdimcnsioral amay,oY a table ik
colwms
# mpovhig tie egiad tibaies!
imposf pavdas a pd
pd.
o Renlar expression
>legulor Expession ox KeEx is used to seach
stivg
oG|o2
pytfion but n module e gor egularpeon.
Rezx Syrext te functonNome(atem, stsin
finctions:
) semch- vetums match object if there is match ia
the sting
Dfndall- vetvms a tist containg al matehes
u)Sub - eplate One og mamy mtches itHG a
i) soltt- getuons a ist hen he hao lbeen
spit at each match! ,0.0.) staiug
import
-'Samim Artar,° kegular Expression
out
efndad (iAvtar,
pint (out) stig)
Retun an
import matchfod.
"Samim treaa, Kgular Expression"
out'e oe fin dal!"Rabul, sting)
out =e
prnt (out)
4one,
impoat re
stilng -"Neoton schol,Reglar Exrpression'
out = e spit(.,
occutYen ces
t : One ox more ccC umences HdT
tie specfed mumber
mUmbey of ccuYren ce.
Dr: coptuse ad
:Retums a mateh if the spe ofed chma ctexs ane
bejnning he s t a i g i e
\w: Rtuns a nateh hee'
staingcontains
charatkxs (charachess fom
rom a to 2, digis fom
e onderscore_ charaater)6u o-q,and
s:Retusns a matoh oheve
chanacter, ke staiv contains
conans a niBe space
D\d: Retvns a mateh
nhee the staig cortain
containss dits
"\ (ronber
inpoat e
stig -'hello 12 hi 89., Ho
patfean = 'la'
45
"4,'5]
deSUlt = e findall (patem, stai) pairnt ( teslt) )t
impost e mpot.ve
staing = 'hello 12 hi e9.to 45 ema) ="SamimaKBar. ee egmail.can"
palfern = Teg=-2 0-+[v-?e204
Pesu|t =eindal! (elfem, staing)
Pairt (gesul) out 2. seorth| agen,sbgenal)
'2', '39, 45|