0% fanden dieses Dokument nützlich (0 Abstimmungen)
29 Ansichten

Python PDF 1

Python notes

Hochgeladen von

Prajwal
Copyright
© © All Rights Reserved
Wir nehmen die Rechte an Inhalten ernst. Wenn Sie vermuten, dass dies Ihr Inhalt ist, beanspruchen Sie ihn hier.
Verfügbare Formate
Als PDF, TXT herunterladen oder online auf Scribd lesen
0% fanden dieses Dokument nützlich (0 Abstimmungen)
29 Ansichten

Python PDF 1

Python notes

Hochgeladen von

Prajwal
Copyright
© © All Rights Reserved
Wir nehmen die Rechte an Inhalten ernst. Wenn Sie vermuten, dass dies Ihr Inhalt ist, beanspruchen Sie ihn hier.
Verfügbare Formate
Als PDF, TXT herunterladen oder online auf Scribd lesen
Sie sind auf Seite 1/ 21

Date

Page
Python t
on 2
Less
featunesOf py thon
Explain
python is high-leveliinterahy e 2
Object objet progaammin Janguae
phython s puplar pYDgYemmng language
beacuseaf l prorides moe,T9aidbiry o
Cod, c learsyniax
of ode,Suppaxt abet
3upportGut.mad
5) Pyrhon taid ts
eandsoon
foundatonthe3ao's
Py Hhon deyeloped by Guido Ven RocSU
ot No hona ReseoTCh n.ahhlde foy
mathmahc S in
carmputesience Netheilh

featuneg
o f Python
Simpleand egu-to-ugelearn
)Pythan 1s simple lonquoge
oth feetoe
S
oycwoYds Simple shuctuse
alsa cleoyly deined
&iS
syntas
p) -thisnakega pythan lagtnig
Beginners
lanquage

(free
and opeon
SouTE –
o) PythonprONOmming
anguageone froal
dvaLlablect theof fca| 0b addre
b) fhe source code s alsoaua ible
forUSe
)Dynamic
9 Pythonprouide
a high-leuel oynemicdota
pe SSupport higindynamletype checng
Date

bTF alsasuppoyaztomatic
allecthion
ganbagefo

ApythonsuppoYS theobiect-ondentpYogYam
Co op) oncepts thet onapsulate codecoithn
Obieb
|kedata hiddingOperatoY
(bALLconcepts
Ovexlodding.nhentance etc Canbe conHer
n pyhoh.

(6ploth
Fornndependehce
can cw0TE with dirfexnt
jpgthorn, plathon
sueh
a)
moc eCwindow,Linux,and oaoithes h,
6)T-expreed terachve n

ispncess
Dpyenon sd ot n tmebuthe
ntepter
Pwe neod notcompiletheprograrbefore
Scalab lei
D Python prbuidea beter stuctye4
suopax
foy large nogyamsthan shell
snpHm
)can.be useo asgipti
nq l9nquage
B

1arge
canbecompiled
tobytecadefor
applhcaions.
bi tding
8)Boad S tandaxd a bery

)Python'
s boyisporqble
&cDsS platfoTm
Compahble on UNIX,Lnux windows mo 4ptsh
Diute
Page

Explainshongmanipulahon
chnaaEesin
Stongare tong indiuke
memam location.
Contigolos
a

the,benef ofasing shongisHhct n

of diyoction8
be aceessedFrom b otth
Cfovnuaxdiedexinq b4Ctoqre &

ndexing o3
Stuts
FaxudTd
Storls-2,-3
Backwardrndexnq
@ shhng means Penformire
manipu)ation
opexctan

shongmainpulatonOpertlhon
Common
choreoG song
3Aceacing tpe
o

doesnot Suppor
-Pytbon chaxacker - a

these aTe treated aset


Shog oFeng Hh

one thus also considered subsing a

Olemen
+ext=Hetlobon
pnnt teyt -1)

1
)slicing
shing
bxtractpotonofShing usinga gling
by usingthe sticind
|ashing opeaothon
(cala)
Date

te y
Python

Olf-
Pytho
8)
Cancatenta
han
Conbinesthe
LLSin the

tSY2

Gp- Hello
Pepehhoh peolso
mes using* aprotoyshmng mulhiple
45hHelloue
Sh2Prag ech)

Gr-HelloMellaHallo.
Esplainstinde lals
one of he most freqeny
tASed veryvensahle.Gotaypeinpykhon
&

=) is is da ta
a Shnlhye tnct allo
y au t stoean ardeneccoilech
on of
irem Celements

Alstcan (reote
ugingSquee
backek
1or thelisECCons atoY,
Separetad
G hy Comma so)
Date.
Page

HAaye.rmny ti£fxenEer
1 can hoUe QnynmberOFIconm
Cinteqet,
tep e
SHaeymay be of icfvent
Elocksing ctC)
Osyolay eistna meyalyesV alu2..alyn
J

egbfcgfore n is
Us+1-E'C",yoyapyhon

singElement
(2) Acoeg
(st are ndexed Stor From foy
tine frst eemen ndcep
O

or Aeqahe
D4ouCan uSe posihiue
lebana
nulsC'opp na ohesny
pnnt CiutsCoJ)

OPobple
cherny
(hicing usky
tigs
slicing oJOwyou to erhactposi-ons
Ane synLax
Lwe cn usinq the
the ronge oF
acesSs temsiA he
la tstby Sua'nq oyperakon
skolorn)
hs Co pple "banona cherng
,
Oragnge "papat"bluebory

L:3]
prnt(Fn'us
Cfomindex Ito 2]
O1PCPple ChPa
PPlebaranou
pdvey chenyrfom up ton dex 2
Second lenend
)Dlate
Page

u's
modiyiag S

helrContent
g-Enut sapp le orange' chey
Pols4]=banana
CDpple bananacbant
Wecn lSooddtnaelemen
al

LSingappend):adds on elemen itb


the
usinainSert)i
inseis
an olermenk t a
Speoife index
Usingox end e)dd muhele.
oemento
Ea uts-tMapple
banong
ffiuSe Qppend icherm
Pint(fnuts)
olp- apple bgnana hesny']

op a pple,bhue.berny
bgnanethe
fo'ot(nuES)
Op -Pappleblueho
ryb0nanch orrg
OYO nge papa
UUecan 20motingetemens
Using ernave
() PemoVes Hhe erst
ocunfnce
Of Volue
usingdel orsee
oplaetheplenfnt
Jeusirgotebur Remove alt olement
ste

UsngPop( omovesan
SescifG
Aterm nd
eleenc t a
x CdfintuFs last
clenent)
fouts 9pple" b gnana cheny'apnl
foutSêmove
(" bo pple)
prnt(fhuks)
5|p-Capple.chery bananD
the 5Oc
RPrnove tunceofapplel
foutSpop(4)
ep apple banana
Renoves Hae olomontot index1
delfriutS
Eoy

O|P banona ]tt


petetetheS element

Prnt fnus
O/pnLJ

sk operahon
Concatenahon pepeoteshan
List2C4,s
pnnttistt1y2)
Clis
afpCl,
2,5,415 coneaterorin
indetwil.
Explaintuple

Sarne as u'stheonty
1e
ffesent
tupledi
simmula b

OA ancecreated
Ttpte. canotbe modifed
isdetinedwithinpacenthases) where
OTuple input-hon
dataiype pgxa
lmmng Singiar
to tae aist dct atype whch alsaconkinS
hetevagene
ouSIregs/e
lements
(Stuple ave used wme-protecdaka ard
fis
4re usudly te tnan s as ircannot
Cre dynamiraly
Tuples
-Cuplesarédefini
ng using
parenthpses
C

tuple-aajeC90.24rO,tyhca"|
Aessing Tupleelements.
you can acees elementsinthetuplesing
indexing & sudg

Col
pintcmytupleg
ene(mý up lesC-11)
cis1)
pintCmytuples

Tlpleoperahoh
ahen
kontaten & Pepehton
ta 2)
t234)
Date
Page

pint c
ttt)
nnt(
*t)

12-34
oFTuple Advanoger
2eychacterjstile
()arderd The elementintuple havoa
Gixedordeandyou them usng
on a ctess

Tuples
(o Heterogeneaug the
qre stove
differhtdata
-type.. Ceginteqes. Shaglatsote)
(a)memo ffieroyTuple us tess
y e
memon compared to st
ammutribe' Once thetupte.ome Crecuted
1ts elementsconnotbe moci'6ed added
OTYEmoved. hisfmmutabiu onsure

sHashableSin
ce tuples
ane lom muta ble
they Can be Used aS Peys 1n dictonaeç
P alltheir elemenS are also
hasable

Sesplan dictianary
esenbictionny
aato
indelal
manipluatian
pe inpythons
On
unordexd Collechon
of kay-pajy Valiue
Dcuhenwe halrea lorgecetk a mount oFdate

3)-th
e dictiongr
dotl type s a
mukblen
modity pdelrCar ueLue
inoictonang
Dute
Pae

)IemoF
iocUtebucy t3&
tco picthonon ant
stcolonCisuseto semat
Separel
endlosd
b Comma e)

ed fromuuune
GCveatng Dictiongies
you conceohe dictiooa usngenybroces?
a

Accessing
eleng
SirgFeys
C'home a)
PyCmy_dict
OJPPyogch
eTuple oprohon
doletng Clem
FStng
dej
i'prage"agc'i
Tegmy.cucname 2s,iyun
telony aictC"age]
print
(my-dlt)
o|P-
hame.pragcstho ci:
Pune

eg-my dic+Chdob!]e"CA
printmy-dict)
-p Nome Jdh
pragat
CA
Q.6pefne knerion5tpeor
FUnchoncolling
asablacaaonk
o G

funchonsdehno
ed sablecod e sedto Pruso Siriae
Tlatedocnoh
aling a finchon
DDeinq funcnononly
a qive i narne Gep

pecfos metfnS tho GretDbe


+he paro
inudoc inTMecranHon Shnrtre
bl ocxsof code.
once tnebasic strurke
oF finction
J

from anthore
t funt
Ho oY n dicy
Hroroua
2ythom prompt-.

9ettttruse
funcion
a

Ane rnchon nom ,followee


by

funchohnama arg15jr2)
3)ex
4cal o fincti
an that peTfor
Ms G task

pintHello
fro Funtton mc

mypunchont)
LoutputHello fvomot Flncnon
cola Funcian cwih eun velue
deF my.finahen():
phntf Hello trame Hello
Praqcti
Abheet
Hello
ny ("Abheet)
funthon
S) wthanguent
ltocala Functian
prtt
c"AYexage o Myandy is,(xsy)
LAusnrobex34)

he
Types offuncton
are thec typescf Funthon
elk-in-functhon.
unfunction
Suchas min)nor)tog tt
velue,pmnt
tne musnun maximum to U

ntar obiecttotnetfmina
Syntay ftge Cabject)

otcin lass

USerdefned
Fnchionha gme neotea by eqremmers
t meet he egwysymentL
2sedefined aewnentoencapo
funchans

paaton theCde moYE moulgr LScbLe


9)Cannet ispredehned 3e
YE
candehns
) flly ustompYed baaed oneqnnet
et qreet-()
greet PintCatella
welcange |
pHeHo, welcore!
Date

)3ui
LnEunhon
functonarepouidedby
LAthese
itsorE

(0)oehare use man pe-defn


elunoton
inpy thoh
Sumen),ype
topure)
pnntian
(MHeld)
pntm(
3o
2O,
1o, 30))
Op

Egplain local&gobalyaniablewithe
10cal Uardble
declaneinglde
jyariable badlyis
a fnetion
khow n aslocal amable
) They c0n used on y inside
theFeinchon
The 1Ocalvanableis Sene Sropes of
in pyhon
V.andble
).ewhen
youcwaYtt to cate
a gobalyanalale

nsidefuncnanthenyou Can tsegohal keyud

der sumfunCong1,ang:

Print Insidehe fnction um: sm


focals
SumfuncI00,300)
pinloukshd
fhé funchon sum:2Sum
globeul
Gobalfunohon
DVanabledeálaveoutslde theBneto
s calledqobalfuncHon
conbe u sed everyahere heth nsiele
5akde tne function
) x- aweSome
der Fnyfunt)
pnntCpython ishx

lesson
2
twhat Smodle an haw cnete module
moddle ase qoup ed tofeknerof foyms Plae
pacleeges
2)'madulesane pimar theCapu)the
which Contains pytho pmgTemming
Be
cocle
deFininq finchons ss uanableteeeoitha
tatrla
Suffiy p appendedinitselassfire
name
Rlaconlenngpy oyhoncodels coled
moclule
AmodulesallooyotoOTqQnize macluda ze
&

yourcode effechueld
Crotea Modeleapyhan
follow
thefollowing toCratbea
steps mocltte.
)create a python hte
-CTete a Hte ds a pyrhOnpog xms
extenslon
as py
Thhsisuownodl:ele wheTe wecanCUne
Date

hteCalled
phedeleipu
dt mocd tule.Py
deftfnome)

detaddCo b
e wn atb
deEsubCa b)
Tetornab

21mport rhe mocdule


Crsate gecond leintheSam d'ehonn
a F e

alledmainhle.wnene canimportthe
m fn
acluleto thetopoFthefle cullHhe S

Srncondh'leisneed to he some
dichiand So thatpython noLosLwherc
tofnd themodtuteSinee iisnotbu ina
module.

detadd Cab)
SeatP ab

dtE6ub Cab)

osult
-my module
oeSUt
2-m oddle
dd S3)
Sub (S 3)
onnt pdoll is on
int( sub ecnons esk2)
Swbtrachoh s2
4 The importstutoment usedimport
is Sper
moduleby u sing/S nome Dete

Bitnodule
3)Exolaih m

l1ed
insto
nDutinmaddoskhon e oreE-
functonalhe3
ibaxonos
tha mnang

Manable,cong
Functions,_classeS orCay
lentS
other vesouree
Pyhon
This module povice
s otmesic & methclateo
fLncians cabatyp
4)hese modulearepoxtot python'sSkandore
instel any eng exhe
Slusing Budt -io-roclule
impax math
pintnath.srtCk)

Tousethe Buit m is sin


module,import
bheImpoy Jesyaard
Somecemmonearple
of au lt29m odwe

ItisuS formathamahcs
e
baavide functions
a for complex
n chong
mathmatice
Opesaho

Cmathap)
pint 4.0/p- 3:14r332

()datatime
Hondlethecac s hme marpulenorn
This odule containe aocs monthda.
hourmuhe Seouno mhisecO
m

nol
issSMCe

-impoY- dareHme
hoo
ateHme.datefime
phntCx)
atitPu 2624-1|-
20 7:58 12076146

4eotenday
(5) calenda
r
-fhis mouleallow
ers
calend
you to Outpu
pouides_addirional
helaeoto thecalendar use fmeion
8
fe egonan

class.cotendatacalendacl kweo bylo)


firs
e- dt
ISUSe foY mang
Impor Calenda
aalandaY

Pintoalendonmorhcyy
c m)
Ymon TU LUend the i Sat Su n

12 13 14 17

ime
is ocluleuSe.foy timeyolateroGs
m

Used for me4Suring hime ovCTealhingdotoy


there ispopularhme module.dya lol in e

Python whichpowide fnchon fo cworlelng


classate

impor tinc
Licks timetic
nt

Ntmby oE ticrs
tg11%686273339
Since l24amJanu0f
SPaeRandorm
FtsefoYgentaingPamdom numbr
useful Foy sliaHons. amesorteshng

impor rondo.m
pinrrandomYondint
Cl,o)
pmnt bondom choice ( Be blueyMgreeHO))
OP-Pandom nt berbeEeenLadLo
Pandomhole
(5esptain paakeageindetuly
prectefineol
User-de ned funchon,.
AfunchianLs Setof stute
ments thattulee

pTduceoukpt
funcHansthat so.clut come oith pythoncalled
ashul+in funchanpython proyidebuwtlnknetohg
C jee pint0) etc but we con lso fneote

•Athetne
dndey
tha-aentten
funan'on
ceteqor
by ary
oEcser-cefinealFine
s come
Syrtda -named):
deffrunction
Sttnnni

3xplain_pro-defned te'
inDe
falnetoParkoge
soppese De hovebevelop ueylorge
ianThat icutdes applct e
many_ modules Asthe
num beYof modu les qTo wS, itbecome3 diEfcul
to keep trace df them al| as he hav
Simila nameg or ncHona

by
t
so me
s necessanyto aLpand orgorizethem
mean och can be ochievodbs4 pockec
p s collochon
of oHhon modulos

4Predefned
ackage
folouENe
bterob
ma th

Someofthe mostpopularmathmehea
Fynehons
oTede6ind n he atn module
fwo math mahcal caans
also dleEin in
col
math module.
ane alsonclude tnqonomehicfunhiona
icthese
apregenlanonYnctlons,
tognthtic functons&
-anglecoYPSiOnFunchon
eié oxispell-known mo thmatcalconsLontcwhch
is defna og the voho of HneciYCU) EbTentefoHe

e4-tmport moth
math Ei
obty1S3635
89793
eassate

(2)Alompy t0r
lume the funrostalpecraqe
scienihc com puting aithpy han

(Eis
fumenapython'ra
uop4isstands
Hishpetonmantmulidmernsio

(9uhapyey s to
qreutealtenabiueg
vSomeofthe e esofNumpy
oduonkaq Tey
tans
Ser oPporkln toperformcalula aros
impor asn

arsT np.

spy
scpsbanythe funchor
b cseAum-pforme
moth ma hce
a se-pyis
Siands pthon
foY Sientfc
puhile nlumpy Hardletne basoap erahon thescpy
aloqmih
focusesan high-Level
dora shuoture
5 cOme oith odutesfo m UeiG
Commony usedHasle inScienihe
pTogranming
tnctttding Cneay algrbra, nregranon
Ssingnalprocess:ng
ASSHAte
Dute

(matplo thb
+ubipypla Sployinq lhare/
Gmatla pe
hd qraphissnPyhon prosTa mmir
on be usediopython snptshell

feetb ce useyinter
oherqrophi feice
tool12ic2
Thoee ae yaiouS plos cuhch can be

plochne
SearreY
Ausedfor eonnq Visul?ikonseepha
charts plos

Ponnds
OPandas Iba
s foy deter
dosianed
oanipulahen & anc lysiç
Cpondas_
is
Nah-pevfo cnce date napulahonnclg
n

Das könnte Ihnen auch gefallen