clAssMate
Date
Page
ython Intenal Assi anment
a) Any (2manks each)
DToo tunctons om calender module.
[Link](yeam, month)
Rehuns calenden o qjvenmonth as stmin
Calendenisleapean)
RetunneA Tanue if yea is a leap yea.
befine package &ajve esample
A2)Apackase is acollechian ot telated nadales
in a
Eg nuappandas(huiltin: callecthaus os).
3 Fanpose ot kinten.
AS) Tkinten in Pythans standand Gnul Libna
Used to CHeate uwindaws. battons. labls
text boxCA, etc.
5yota o lass
AYdaSs ClasSName'
defminit(se))
self data e0
5) Aduantage og pandas.
A5y Handles lanae dataseBs esfiuenty
2Pouides data cleaninagltening oupiog
3 Suppots ime-seniei openatous.
Inteamates with Numfy &MotploHib
clAssmate
Date
Page
Rise statement (syntax e enample)
AOnise Exception("EnNaNMcssa e)
Used to manually gnause exceptions whco
speciic enhom conditions occun.
DKey featunea ot Rythan
A)Easy & eadable
zllntenpncted k dynamicaly tyeed
Obiect-Caniented Ltunctional.
4lnge libmaysuppomd
5Pontable &entensible
)Access value io dictionaY
AR)d= "name':"Mansee " Cage
ase"i2o}
Pnint(dCnamne"1)
phint ([Link]("age)
Atempt ant
functions Aquments in fythaa
)functions in Python can accept difsenent kinds
og angumnents.
Tgees?
fositional Anauments
Values ane passed in the Same o1den as
deiaed
def add (a,b):pnintla +)
add(5o)
clAssMate
Date
Page
2
1Keond Asiauments.
Panametes ae passed with names.
add(b=lo, a=5)
Dejault Ashquenents
I value nat quen,default wil be used.
de ameet(nameeGhucst) pnintC"Hello'name
gneet(
4
Vaniable-length Aaauments
anSmuliele positianal values.
**
Roanes-’Multiple keyocmd values.
des shou(tamqs *M kuwanas)
pint(angs, kuaiqs)
showll,2,3, name "Mausee" aae =20)
Sianiicauce
PoTouides Hezailiky,meduces medu ndonc
imphoves meusabillty
sianitcance ot i-ese statennent
A2)1 The itelse statenent is uscd tom decision
Imaking in pythan.
2 checks conditious eecutes ditenent
bocks o code depending on whe the
condition is Tonue on falsc.
2
Syntax
i conditioni
#Tue block
else:
# False block
classMate
Defe
Poge
4 E x a m p l e
a4c18
psint(Eliaible po vote)
elsci
paint("Not eliaible)
slsignificance Helps implement bmanchiag
lotc in sheal-uwamldpanablems like laqin validation
1eliaibilit checks, anadin systems
Method Ovenlaading
)lo some lanquaqes(like Javalc+,Methad
aenloading alouos malHple ganchiouS with the
same name but disenent panametens.
Lln Pythan Tue ovenlaading s not suppomted.
llastead, e Use deault anquments o Tasnas
to stiulate.
2 Cscanaple
Ldass Math:
de add(selfasobeoc =0.
1etun a t t e
meMathc
pníct ([Link](5,1)
psuint (madd (s,lo 20)
thon allouws one me thodname to handle
dittonentnumbens o ansuments gjuen the
edect of ovenloading
classMate
Dat
Page
tplain any 3 widqets in tkinten.
AA Label
Displays teats oarimaqes.
om tkintea impont
100t =TkO
Label(moat, tent Welcome-pack)
[Link])
2
Entay
Used to take sioale -line input 4mom Wsen
Entay(hoat).packs
3Butbn
Eneutes command on dick.
Bu tonlnoot tet'lickMe" coMmandenoot
auit)packO
Gà)AHempt Any 4
DRython lhoqam: Calulatosn dass
lass Calulatos:
detadd([Link]): hetunn a
de sub( self,a,b): netuno a-b
det mul(sel.a,bnetuna tb
de7 div(selh.a, b) netuno ab
i bl=O else "Diuision by Zeno!"
c= calulatoO)
pnint ('Add: cadd o, 5))
pnint( Sub: C sub (l0,5)
paint Mul:cmul(0 5)
paint'Div:cdivC1o,6)
clksSHAte
Date
Page
AsupenCOMethod Lin Aython
ANsupen() s used to call the panent dass
constuctoet/methods inside a child das3
2 Ensusies code meusabliy avoids 1ewriting
Example
dass Paent:
detinit(selt)
pintPanent ini
lass Cuild (Paent):
def-init(self)
Supen().-init_)
pnint( child init)
3Eplain me thods son qeoMetny Management
in tkinter wit example
t3)pack)
Anhages widaets in blocks.
Widqets adiust automatically accondin to
available space
om tkinten impmt
Shoot = TkC)
Label(1oot text="Toppack(side =ToP)
Label (soot,text ="Lettpack (side =LE F)
Label (atoot text= *kiqht)pack (side =R1aHT)
[Link]
elssate
Data
Page
Places widqets in table-like sBnu choe
Mone contool than packO
aom tkinte impott
S1oat TkO
Labellaoot, text s"[Link](orow)s O. columna)
Entay(root). qoid (aouw s0 coluMn)
ButtonCoot teata"[Link] (moosl, column:
[Link])
3placeO
Places ideBs at absolute positious.
Gaives he most contnol but lessHeble.
tanam tkinten iapont
100t =TkO)
Labiel (10ot,tet=Hello-place (ee 50, y= 50)
Buton Cioot, text1ciekplace(u=100,y 1o)
[Link])
9Wnite_python pnosam to accept stain
91emove charactens wich have odd inde
ualue of quen sting using usem de7ined
tnction.
ASdelf memoueOddl (sBaning
toiin auge (len Csining))
1esult t=
31etn Meult
staing il
sinput ("En ten stnin).
pniot C'omiqinal staning )
pint ("Mocified stainsemove 0dd cs)
dseate
Dete
Atermpt Any L
Anite Rythan gunchon to calculate tacto íal of
rumbe wbing mecunsion.
Addef toctoniaCa
1etunl
else
etnnn tactoial(n
numa intinput( EoteNumben:)
pnintgFactanialonunm;ist sachnialCnu)
a) DiffnenCe bebeen list numpy anay
A3) L'st NumPy Anhay
Built-in data stuctune Psiouid ed by nunapy
in Rthan libgnany
eCau sto s1e heteno sene-StoeS ony hoa Deeneous
Ous elements. elements.
3 ConSumes mO 1e Uses less memMOny
memoy
4Limited bui'lt-in Rick atheraaticalL tnctiauS
tun cti ons
Can qmouw dynamicalyFixed once cneated.
classMate
Date
Page
eWite Giil pitoqmam to cneate backanound
with caanging Lolos
A)impa tkinte as tk1andom
Shaat =tk. Tkl)
calons =C'Sied' «blue'qheeniyellow
ldes changcO:
1octconti (ba: handon choice(olaas)
Moot aten (iooo, daange
changc
moat mainloop)
5) Eplain idaets sesizins wiHa example
AÐ)Tkinten,me wi dacts can be 1esized
usiog
geometny auaaen [Link]).
2
pack CillLepand) stietches widaet n x, o
both dinctious.
3 Gnid(stickyueiaht)mesizes oidaet inside
ts gnid cell
Lf310mtkinten impomt
S10ot =TkO
btn Buton(oot tet=Resize Me)
[Link]((tll=BoTHepand eTue)
dAsSMate
Date
Poce
aite 3 dikenentd
was to
p
inMpost mModule
module
o t
ADIImpont whole module
imp0t math
psnint Cma th. sqnt(I)
2 Impont Module with alias
impoMt math as m
pnint (M-Snt(25)
Inapant speciie tunctio nldass
0m Math impot Sqt
pnint (sqhB (3)
olymanpkism meaS
APalynamp'sm eaus "many pnmIn Aython.
it allouos the same juncthion me thod og openatOM
to behave diffcneoty depending on ohject o
dataype
2Types
Function Polymomphism
Same kuochon can uaank ith difnent data pck.
pnint(en ("He lo)
pnint (len(li2,3 4))
Openatoe1 Overloodina
Same apenatom peaans di7emet openathons
On
difnent data ypes.
pnint(l0+ 20)
Aint(Hi" +180
cdaSSate
Date
Page
Methad Ovetiding
Caid dass ede kioes method oB pnoecte
pasent oass
class Animal:
deg Sound (self)
pmint"AnimalMakes a sound
cdass DogCAnimad:
det sound (sel
pint ("Dos banks)
[Link])