Python Notes
Python Notes
Featuves of hon:
st is an intevpreted
Taterpeed pyaugngg
4 Jt is dn trteratie
?nterati ve
anglangage
K JE is postable
Propam
n euecufon s
Kron as pocess.
* *charackr st ow ane
digta o to 1,Aabdsfom A to or
Token:
Unders co re .
R Jt Cannol storb oîth a diqit.
ao be used n fdentifer.
Iitecals 0 Constants:
hee tupes
Vañatles:
a=5
1-"hello
Uote
tye of the VoRable oe arn you
you woant to know the
tyre(Vanakle namc)
functon txcepl?orn
nt () Corvets
Spit foc tion:
Thts mthod is
Converts ang data tige to fod.
Mze function
Ex:
4t ts a oupt tunctor ued to rint.
Peat (messog)
f"You
(o)
print You are
pirt(92, Sep and -)
'o, * name ab'
oupt
lo 20o 30
Pit(f'am ýnas
Note
mulpk vafsble.
lon allaas asstgn a shyle Valae to
ale lne.
Sptfnction:
This method is wied to clta s hieg trto a lict.
Var,rarre -
Ex:
tzt = welconeto st
xIrpts
Print (:)
- uniersty
trt-plito
Asekn function
his -function is used to reod mutipla vatue s na Stale lre.
Note:
f-toimatted data
Rnite
all the Vaitables
• when using onf infot of
an a sting
braces ave Yead and replaced b their Value.
E:
age
message =f"You are fonet yeas old
pfnt (messog)
Lfbrany
module
Note
because of
PuM (Python Vitual macline):
Data typ
fundamental daa hype (PRitive dala ype):
are uSed to Stoye
PRsive data types ay
-The Varioble Conains ony Shgle Value .
sirge Value.
shudures
datadpes
fozenset :
L1st:
.A list Ps a Collecton of odercd element's chee dugliaes
a1e alowed
. Lists are muta ble.means
Yemoved
os
o modifed after
elements an be
(reaton.
odded
E a= o20,3aJ
Tugple:
bat-his is îrntable. means tts
A Tple fs sîoflar to list
eatisn.
elements Cannot be chanqed cafter
rozen seli
Diet:
•4t stores data în Key o d Vaue pats, ohere each
pfat (peson
iname,"aliee
["hame])
, 'age':si
Bytes:
3tis a fmutable sequere of bytes, often used to repu
binay dala. Convests ist fnto bytzs
Suta: se 'b'a)bytesc
Note
Splo bytearay)
soler t Saots Tndering and slicg
vlist =2,34,61
Sire- 5
oá = bytes (rlist)
bytssi2e)
pst(an) print(ar)
a - [215,G6 61)
t Con vet the list of întgosiobytes
b-byesa)
oe: cc
pat l5)
blxdBc'
usirg byeata S 2e -5
•pimehubers - [23,5, 1]
A Coavets list to bfeaay pRt (ar)
byle.anaybgixag(pime hunmba)
loood)
28
2:Operatos
Someo
94thmtia operatos
(
(
laial opa
Estáe opealo,
(terkay e
Athaneb npetms
eret
rit ()
A)float diicion
Pelatora oRratasi
hese opeetrs
au used tb (orpare
ote!
on Fal)
boolean data (True
ticse
operato awags return
Lejical
hese opet
operators
b
used tb Gnpare
rators ase uced Grnpare hoo o more relatonal
epesions
and,or, not
are tue.
* and returns te oher both the statemnents
are tue.
?f one of the qiren statemerts
* or Tetuns tue
X notReverse the reSult.
Ex: a lo
b= 4
Bitose and
Kenbarshie operos:
hese cperators used to fa Sequene is reseñt i
lo cation:
is not eluns e tf hoth Variable s ahe nol Same
object
EXI num15 pint (nurot is num
Num9
a-[l,3]
5
nt (ais b)
pint (ats c)
Note!
prfeere blo l='and 'is'opevoton
is a relatlonal operatot.
is' s an 7denti opevatov
Vales Df too Vavtabes, hevcas
'is used to (ornpare the.
boo
is opevator is used to Conpare he memoy locatforn of
Variables.
Jndentation
each Iine.
Operator Prede ne
dt descsbes the or der in wohich opeations oe erfomred
ohen an epres ssion is evaleated
Noe
ssocav:
too or more operas have lhe Sore prece dena
tuwheneVer
precedenn
hen asoctkidy de fines the order ofl operatiors
foportantfuce
• stvip():his method 1ermoves ary chitespaces in the
:'
br
and ending
Bl me ssaqe Learn Fglhorn'
ole:
Ea' Car
brand'; "fordy
"motor':'Mustang,
Year :1961
2= (ar. Voues()
Pint ()
iterable object
|
it reliarns orderi
n a'serding
a - (,,
=) 12)
Sorted a)
pint
-Totersectioo (): Thismelho reisns a set thol Colaos
foportant fuoE
stvipt): his mehad 1emoves ary hitespaces Tn theba
and
3 mess aqe.
pint (messane. sti
Learn fglkor'
ole
p)
aluesc: this method retuns a vieo
Conlains lhe Values of
o bject
adictonay as a list.
,
that ohi
E* Carf
'brand':"fordy
'motor' 'Mustang
VYear:1964
2= Car. Vaues ()
Pint )
•Sorted co:This furnctibn veuns a sorled tist of he Specia
iterable object
>You retiyns
Can pecify asendingdes cerdng du by defuad
|
it n order
tsending
Set2 2,3,43
Sets teasec lioo t, st)
Pint(st )
Set3 -(set1 & sela)
Prnt(set )
eturns the loalrg point,'e rorded
TOund(: his untion
Vexsion of burobr
speed nn of ceimdt
oith
3- Control
*Of Tee types
4 )Conditional st
e) Looping st (tterative)
st (unadlitional
)
Conliol stalerent:
*Condtioncl stakmerts bas
the ouder ececution
of
Decídrg
Conditions
are three thypes of odiBons
)
There
one block ie teue black)
MShrple îf (oorniains
(3) elf
ifete 4 Condition:
statements
else:
stae ments
a=fnt Bnputo)
if a zo!
piot ('Positive
else :
f year0
( and Yeao=oor Year
print LeapYea
3- ontol statements
Of thae
of types
) )Condition al
e) Loirg st
Tumping st
st
(tevatve)
(uncoretitoral)
)There
D
are three
bloc Ks
ie
ie
tue
tue
bock)
L False bok)
ifelse
.
4 Conaition:
Statemests
else:
State nents
Yeînt (rpt)
yearH==o and YeaooD0 or
prnt ( leap Yeai)
Year. loo|=0 :
else !
pint[ a Leap Year)
etfSyo: t condition 1:
Blxk_1 statements
ebf conditian2:
Block-2 salements
e f Conditian3!
Block -3 stalements
else:
statements
a- înt(input)
b int(inp)
c-nt (nto)
deiatinpt )
if asb and azc and a>d!
pint as qreate st')
ealest")
else:
jrakst).
Unit stalements;
Owhk loop
tlk loop toe an encecute statement ontill he Condtoy
Vayiable.
is tee. it veqires to de foa an indexing
Syptas
while (Condition):
Stalemenls print(i)
it =2
er loap
Tor loop lterate s over
statemernt
X- 10,15]
pint (1)
Note
Hor loq doesnot tequ'iTe an Yndeirg Variahle.
targe rmethod:
used to
a list of nurnbers which is
4t gene rates
teroe Dver uotth for loopP:
a ronat (atat,sbp,slep)
Nofe:
Plparamelers nmust be htegers
All parame ters an be te nt a)-e o.
(obreak
) Conlinue
te
print ()
break
break
int (1)
it=1
If13
Contiu
prt)
Nested loop :
A loop Pnstde anothe loop is Kn oon asneiled n
ole
for in range (1,0:
Shape attibute
:
the number of elernerts n tach
he
shape of an amy is
dimens on
Note:
an altibule Called shape that rib
elements
E!
cinen Ts.
Shape