M W
Page No.:
YOUVA
Date:
Ghopter 1Introduction
to Pgthon
I11 What s Python 2
thon is a general-puipase,dynamic high-lexel
and
inteapueld pragamninh kanguage
"4 is designed to be simple and easy to lean, making
it an idea chaice. for bedinners
|: One o the key shenghs of Rgthon is iks vesatility
Pethon suppatts the obËect -oriented proqramming
appipach, allaging devdlopets to caeate applictins
utth organixed cthe reusable ade
12 Featues of Pytboh
Puhon's suntax is designed to be clent
and neadable,making i easy for bath begin ers
QCuTiOUS=proganme
MT W TFS S
Page No.:
YOUVA
Date:
Singliciy
Igthon emphasizes simplcits and avaids
Complex såntak, nakind it edsier to leatn and use.
campared to cther progranaming languages.
Dunamic Iyping
Python is dunamicalls tuped, meaning you
dont need to explicit declare vauiable types.
Latqe cBandard libiars:
Ruthan provides ayast standard libiazs
with reads -to-use modules and functians for variod
Hasks.savn devebpers tinne and Purnchion ethorts
Lin implemrtibg common Aunchiondlitiea
Cbiee -Oriented Prgramnin (oop)
Rethon sugpatls the cbjuct-aienked
obiect-
proqramming paradigm, dlowing for fhe ceation_and
manipulaibn o ohjecclasslss and inheritunce,
Class - Platfom Compatibiltyi
Pethan is avalable, an oulliple platforms
inducing Jalindous_macOs .cind Linux,aaking it
urious-proqiamner
MTWTFS5
Page No.:
YOUVA
Date:
Extehsive. Thurd-Parky librcries
Rgthonhas a yast ecasystem ofthird-park
libraries and Hanewotks that expand ils capabilities.
in dierent damains, such as webldevelopment data
|analysis cind machine. learning
|nterpxeted Nature
Puthon is an interp1eted Ianguage.meaning
it does not requice compilaion: This resulks in a
|faster developmentcudle, as aode.can be xected.
Ldirects uwithout the need fora Seprate Campilation
step
nteg1sion apabiltias:
Rgthon can easily integake with other
lanquages like C, Ctt and Java,alowing develapers
to Iexerage extstíng codebases gnd libiartes.
13 Aplications ot Rython
Pathon is widels used in yariouS domain
and afens Aumerous agplications due to its ferbilets
ond ease of uGe Here''are Some kes areas here
Rythan Ands aplicdians
M T W T F S S
Page No.:
YoUVA
Date:
WebDevelopment
Rythan is extensivelg_ used in web devela
pment famewoiks Such as Diango_and Flask These.
fiameworkS pravide efficient tasts and libigries to
build dånamid websitas and web appli'cations
Data Analssis and Visualization
Pathon's Tich ecosystem of libiaies inclu
ding NunmP Pandas,and MaBplotib,make t a popu
lar chojce for catBa analsis and visualization- edab
[les prafessionals to procAsS ,manipulate and yisualize
data etechisely
-Machine Leayning and Arifeia Inteligaence
Python has become the go -to lanquae
for noachine earning and AL pigjects lbraries Iike
Tensot flow,.keras atd sikit-lean provide powetful
toals for implementing omplex alqorithms and
haining models.
1-Atomatian and Seuping'
Rethon's easy-to-read suntax and apid
deyelopment cycle. make it an idea choice. -or
autonaion cnd riping tasks. H is commanls usedl
airious-.proqrammer
M
|Page No.:!
YOUVA
Date:
14 Python hstallation
T6 dounload and install Rytbon, tollow these steps
For Windows
Visit the official Pgthon_ uebsite at
JM Rthon.arq /dounloads!
| Download the Python installer that matches youn
aystem tequihements
| On the Pagthon Releases for Wlindaw paqe. select the
liok for the latest Ruthon 3xx eledse
Scrol down and choose either the "indaws X86
G4 execuable. installer" for 64-bit or the "Alindows
x86 executable installey"or 32 bit
Run he douwoaded installex and falloua the instu
chions to install Puthon on your lindows sskm
For Linux (apeafcaly Ubuntu
Open the hanty softuare. Center folder on your
Linux
From the Al) softwaye drop -doun list box, select
Conious-proqrammer
MT WT F S S
Page No.:
YOUVA
Date:
locate
on it
the enhy for Python &xx and double.-click
click on he inshall buton iniiate the installation.
piocess:
Ohce the inchallion iscomplete, close the Cbuntu
SoFtware Centre Folder
16 fist Python Progtam
alriting your fist Puthon proaram is an excitind
step touwar leauning the anguage.. Here's a
simple example ta qet you started:
ahated
# Prinin Hello alagld Usinq Pythan
print (Helo wlanld ")
letss break down he code:
The print() unctian is used to display the specitic
messae or value on he Console.!
In this case, we pass he string "Hello Aold" gs
an argument t the print()uncion.
cumiQusproqrammer
MT W T F S
Page No.:
YOUVA
Date:
The. shing ia enclosed in dauble quotes
The # symbol ind icates a comment in Pathon
Gommensare ignored by, the interp1eter and are.
Wsed to provnde explaindtions or hates tato the.
code
Qumious-sproqramne
MT WTFS S
Page No.:
YOUVA
Date:
Ghapter 2Modulks
Gonment & p
2-1 Modules in Puthon i
Modules provide. auua to orqanize your codle loqically
Instead oE having all your code. in a single. fihe you
Cdn split it into mutigle madules based on theix purpose
Fox example. you miaht haye one. module for handling
input Joutput' operations, ancther or mathematical
cdlculatiobs._.and another sor data manipulatian
JAhen you want ta u_e te functianality foma module,
you can impart it into Your cunen! progtcm or another
'module
This allous you to,_ accesS and se the funcians ,classes
and variables deined within that madule. B4 importing
a module you can qvoid wrting the samecode
repeaBedls_'and instedd 1euse She code deßined
inthe odule
@ rious-proqiammer
ML W.IFS
Page No.:
YOUVA
Date:
22 Three Main Types of Modules
Modules
Built -in External User- defioed
modules Madules Modules
Built -in modules:
These are modules that come pre- installed uith
python.Theu are patt of the stanzaucd libians and provide
la wide Iahge of funcianalities:
"Examples include modules like math for mathematical
operations,Iandom fou qeneratinq tandorn numbers
Ddte Tine for woiking wth daBe and timesang as
ior naacling uh 'he openaing gsBan.
Built-in nmodules are. leadlils_ quailable far use. with
out the heed for additanal ostallatians.
IEsternal Modules:
" These. are. modules that ae Credted bå third-pat
deuelopers and gre hgt part of the stdndatd libdis.
Qcuious-poqiaine
MT W TFSS
Page No.:
YOUVA
Date:
They exlend Aghan's capabiliics by _proviing additi
ana funcional.tias for speciic purpase. Exteinal
modules can be dounloded and installed using pack
ages managers like pip (Pgthon Packaqe. Index)
"Popular external modules indade numpy foy nurmerical
Coaputatians pandas for data manipulaion and
analysis. maslolib fo data visaltzation dnd
Tequests for making Htre Tequests
User - Defined Modules:
These. ane_modules cieated by the iython progammes.
hemselves. hey allow users to arqanize' their code
into sepiate files and 1euse. tunciandlity acrOSS
muliple pragams.
Wser-deiined modules_can contain funcians.cdasses
Vaniables.dnd othex code that can. be imported and
used in cthex Rython scuipts ot modules
a3 Comments in Python.
Conmnens in Pyton are used to piovide erplanatozs
notes Iitthin the code Hhat aie not exeauted oz ne
Qutuous-ploqramne
MT W T F S
Page No.:
YOUVA
Date:
They are helpful fo impraxing_ code readabilts and for
leaving reminders oi ekplanations fo ather'developers
wha night woak with the code in the future
In Pgthon Comments are denoted by the hash symbol(#)
follouwed by the comment hext
H's igportant to noe that comments are meant for
human xeacders and are nat executed by the Pyhon.
inkerpreter Thergfoxe they have no impact on he
pIogram's Funchionalits & pertoarmance
pes of Comments
Malti-line
Single-line.
Comment LComment
1 Sinqle line Conments
are Used to addCode.explanatozs.
Sinale-line Coaments single
notes or omments on a line of
They shat with a hash Symbol ) and cotintue, untill
the end oF he line.
Qurious-proqiamme
MT W TF S S
Page No.
YOUVA
Date:
Anything auitBen afer he bash sumbol is considered
a ommert and is iqnored by the Rythan interpreter
Here 's an example:
# This is a single-line. Comment
X=5 Assianinga value to the vaaiabe x
|2: Multi-line Comments
Muti-line Comments,also known as block comments
allou you to add conmments hat span muHiple
lines
Pgthon does not have a built -in syntak sperificalls.
for multi-line. comments, b you can achieve. thisg
hy using hiple quctes (eithex'sinale ox doube quctes)
tocteate hing- 4hat is a not assigned to an
Vaxiable,. Sinctis that not (sed elseuhere io
Hhe code,t acs as a comment
Here's an eximpe'
This is o muti-line comment
t Can Span QcKosS matiple Ihes
QCUTOUS-. proqrammer
MT WT FS S
Page No.:
YOUVA
Date:
23 What is a pip
In Simple terms,pip isis aapackage
package fox Aython- H
Sands o "Rip istals Pakags" ox "Rp Jnstalls
Python' Pakagss
When working with Pahon. you my need to use. externa
libiaries or madules that pioride'additional funcionali
ies beuond what the standazd libas aters. These
libigies are often developed by the Python ommuntt4
and are Qyatlable tor andone. fo (se
Pp makes t eass to install,nanage. and unistall
these extenal haaies
bxanes Hhelgs you find and
download the libaxies yoL need fian the Rghon.
Packaqe Index (pyp) ohich is arepositox of
Pathon packages maintained by the community
coanmaaiks
pip. you can instal aapackage by tunninq a
simple cofamand in soutr Beiminal ox command
QCuvious-progiamner
M
raya tia
YouVA
Date
Ghapter 3: Variables.
Data Iypes &Keguords
31 Vaniables in Python.
In Pgthon, vaiables ae used tostore Value,
S that can be used laBer in a program You qan.
think of aiables as containess that hold data
hat makes Puthon unique is that you don't
need to exnlicitiy declane the type af la vaaiable.
You simpls lassiqn a yalue. to d variable using.
Hhe " =h operatox uaing
" FoL example., you oaan clerte a vaiable called
'name' ahd dssian ta value hke his:
hame =
Yaanyesh
Here, "name" ia the variable name, cnd "Yaanyesh
is the yalue qssianed to it Agthon will auto
maticalls determine the tupe of the variable
umous-proqiammer
MT WF
Peze No :
YOUVA
Date
based on the value assigned totnthis ase,
the type of the variable" name" is a sting
Vaiables in Puthon_ can bold differert types of data.
such as nurnbets.,shiaqs, lists, or even more complex
objects. You can chang. the value. of a yaaiable kt
any time by assiqning a new yalue to it. for instance:
dge =25
Qge =26 #updaing the value cf 'aqe' yauiable
Potbon aleo allows you to perfom cpertions on Vazi
ahles- fon example., ou canladd,sutac, multiply
oL divide. yauicbles containing numbers You can
eVen combine vauiables containind numbes. oF
dillerent Aypes using oputatos for instance
X=5
y =3
i= Xty # he value of 'X' will be &
greeting =" Hell"!!
name = " John
MessAe = greetingt tname # The
yale of " messagill be "Hello Tohn"
amous_ProqiammeY
M
Page No.t
YOUVA
Date.
Variables p1ovide a way to store. and manipulate cdata in
Pthon, haking it edsierto wak with itfomatonthiau
ghoutt youprogiam By giving meaningtul names to vazi
ables.you can make your code mÝte readable and
undexstánble.
3.1.1 Tdenttier ington
In Puthon an idenifier is aname Ised to identif
a Yauiable, function, chss,module or ans other User-defin
Led chËect- An identiier can be made up of letters C
both upperdse and loue,case),diaits, land underçcores
)Hauevex, it must sBartwith a leter or and under
SOres:
Here aie Some impogtant aules to keep in mind when
JOakinq wth identitiers in Python
- Valid characters i An identiers can contain letes
(a-3,A-2).diits (o-9).and underscoies(#cannc
cont-ain spAces oI Special chatacters like,#,or $.
Case Sensitiyits : Pothon is case sensitiye, medning
upperease and louercase leters cIe
ate conaidered dit
aeht So Mmuvas and "mqa" are tseated as.
Atao ditteron identikiexs
.Resexved wors Pathon has JespIved wordsalso
known as keyuoads that have predefined meanings
CuYious- poqiaalmer
YWA
in the lanqucqe. These wonds cannct be used as identi
iera. Examples of TeServed words include "if"while"
and "def"
Length i lcenlifiers can be of any length Houever,it
is 1ecommendended to use meagingtal and descriptive
names that dre non- excessivels bng
Readabiliy: His qpod piachice o choase dessi
ptive. names for identifiers hat convey their purppse
br megninq This helps make the code moie'redd ab
le and ufderstndable
Hete gre somne Cxamples of vald identifers in Rghon:
"my_Vaable
"COunt
"total-Sum
"Pl
. Myclass
And here are some examples of Invalid idenhers:
" 123abc (starts wtha diqit)
my- variable( containg a
"ifla reseTYed word)
my yar(contains aaspae)
Qurious-progiammer
M
Page No,:
YOUVA
Date:
32 Data T4pes in Rython
Data types in Rython xefer to the ditkerent kinds
of alues that can be assiqned to variables. They
deBeimine. he naBure, of he data and thepoides operations.
that can be performed on -therm Pubon
Seyeral buit in data types,induding,
1Numeric:
Rython supports dihenent numerical clata upes,
incuding inteqers (uwbole humbers).Aoatind -poiat
numbers (deamal numbers), and conmplex humbers
numbers wth real and imaginqs parts)
auintegers (intfiactiond
Inteaers jepiesent whole. numbers
mithaut ans tactana part FoL example,age =25
h.EloatingPoint Numbers (Float) Flagting- point
numbers ep1esent nunmbers uith decimal paits ox
faions Fbr example,pi 23:14.
CConmplex Nuobers (complex): Complex nambers
have d recal and imaqinazy past They aae dengted
by,a combinaian. a rea and imaqinan number,
suixes uwith oxT fot 9ample
Diciandaies are key- Value pairs. enclosee in
QCaniouSproqianimer
M W
Page Mo,
YoUYA
Date
curls biaces. Each values_ is asso ciated with a unique
key allowing for efficient lbokup and 7ehieval
Fo exampleperson == i'name': John', 'aqe':a5,
'city' 'Neu Yotk' .
3.Boolean:
Boolean (bool) : Booleans iepresent ththalues
cithe, Taue. o False Theylare
lare used
used Fos
Foslaqical
Operations
Tue
cnd condihions For example., isalid
4.set
Sels (se): Sets gre enclosed unordexed ollections_of
unique. elements enclosed in curky
curky braces. They
bIACES
qre usetua for, mathematical operationS such ds
nion,inteisection and dijeence.for example,
Fuits =apple' 'banana,"oranqe
5Sequence. Tpe
Sequences, xepIesent a allecion o eements and
inclade data Hupes like shings Jistsand tuples
Shings. cre usd to sore. teual dlata , whil lists
and Auples dre used to stored ondered collectiops
ot itehs
Gings St): Shigs are Sequences af chdrace
Quious-proqigmmer
Page N
YOUVA
endlosed within
hame ="John"
sigle cr double qustes. fu example.
"ListsIis): liss are. ordered seduences of
clements encdased in _sgcane. backelt Each elemen
can be o any data type For example., nuraber =[1.2
3.4)
Tuple Ctuple): uples are similaL br Jists but
Aie imautable, neaning theic elemens annot be
changed once deined They are encosed
ses foL exampleaoordinates =(3.4)
in paxanthe
3:8 keulwords in Rython
- keywords in Rthon are special wads that have. speai
pic meanings and pupobes within the Pthon lahqua-
je Theq
They are reserved and anno+ be uSed as azi
able names o identifiers
kenwords play a cucia role in deining the shuctue
and behavtour of pthon progans.
kestpords are like. builaing blochs that allowus to
CIEate conditional sBatchients, loops, -funchiansclass
handle enoIs ,cnd perfon other Impoztant operation
They help in contialling the flaw the praquam and
specity hou dihertnt paats of he tode should
@cuxioUS-praglammer
Fou ekample., the if, keyusod is used to check condilion
and perform specitic actions based on thosç conditi
ons.The fo land while keywords are ysed to
areate
times. Ioops.Hthat repeat a Block of code maHiple
Tbe de keyworcd ie used to_define funchons, which
are. xeusabe blocks of code that perfom specitie tacks
ist al keyoand in Ryhan
False. qwait else impotpas.
None. break except Tgise
class ís Teturn
Tiue
gnd
Finaly
Continue for lambad ty
gs def from nonlocal while
qsser! del global not with
elif
QCuTiouS-.progiammer