0% found this document useful (0 votes)
2 views6 pages

Python Basic

Python is a high-level, interpreted programming language created by Guido van Rossum in 1989, supporting both object-oriented and functional programming approaches. It is known for its simplicity, ease of debugging, and extensive libraries, making it suitable for data visualization, data analytics, AI, web applications, and database management. The document also covers Python syntax, comments, variables, and their scope, providing examples for better understanding.

Uploaded by

ry0355154
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Python Basic

Python is a high-level, interpreted programming language created by Guido van Rossum in 1989, supporting both object-oriented and functional programming approaches. It is known for its simplicity, ease of debugging, and extensive libraries, making it suitable for data visualization, data analytics, AI, web applications, and database management. The document also covers Python syntax, comments, variables, and their scope, providing examples for better understanding.

Uploaded by

ry0355154
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Py

thon
 Pythonisady nami callyty
ped,GeneralPurposeProgrammingLanguage
thatsupportsanobj ect-ori
ent
edprogrammi ngapproachaswellasa
functi
onalprogrammi ngapproach.
 Pythonisalsoani nterpretedandhigh-
levelprogr
ammi ngl
anguage.
 I
twascr eatedbyGui doVanRossum i n1989.

Feat
uresofPy
thon
 Pythonissimpleandeasyt ounderstand.
 Iti
sInter
pretedandpl atf
orm- i
ndependentwhichmakesdebuggingv er
y
easy.
 Pythonisanopen- sourceprogrammi nglanguage.
 Pythonprovidesverybiglibrar
ysuppor t
.Someoft hepopul
arli
brari
es
i
ncludeNumPy ,Tensorfl
ow, Sel
enium, OpenCV,et
c.
 Iti
spossibletointegr
ateot herprogr
ammi ngl
anguageswit
hinpython.

Whati
sPy
thonusedf
or
 Pythoni susedinDat aVisualizati
ontocreat
epl otsandgraphi
cal
representati
ons.
 Pythonhel psinDat aAnalyt
icst oanal
yzeandunder standrawdatafor
i
nsightsandt rends.
 I
tisusedi nAIandMachi neLear ningtosimulatehumanbehav i
orandt o
l
earnf rom pastdatawi t
houthar dcoding.
 I
tisusedt ocreatewebappl icati
ons.
 I
tcanbeusedt ohandledatabases.
 I
tisusedi nbusinessandaccount i
ngtoperf
or m complexmathematical
operationsalongwi thquanti
tativeandquali
tati
veanalysi
s

St
art
ingPy
thon:
OpenPy t
honI
DEoranyothertextedi
torofyourpref
err
[Link]’
s
understandpy
thoncodeexecuti
onwiththesimplestpr
intst
[Link]
thefoll
owingi
ntheIDE:

Pr
int(
“hel
l
owor
d!!
!”
)
Nowsavet
hef
il
ewi
tha.
pyext
ensi
onandRuni
[Link]
l
lgett
hef
oll
owi
ng
out
put

Resul
tshow:

Hel
l
owor
d!!
!

WhatisSyntax?
Insimpl
estwords,Sy
nt axisthearrangementofwor dsandphrasesto
creat
ewell-
for
medsent encesi [Link] er
l
anguage,thesynt
axist hestruct
uralarr
angementofcomment s,vari
ables,
numbers,oper
ator
s,statement s,
loops,funct
ions,classes,
obj
ects,etc.
whichhel
psusunderstandt hemeani ngorsemant icsofacomput er
l
anguage.

ForE.g.a‘comment
’isusedt
oexpl
aint
hef
uncti
oni
ngofabl
ockofcode.I
t
star
tswith‘#’
.
Moreoncomment sinthecomment
schapt
er.

Pyt
honComment s
Acommenti sapartoft
hecodingfi
lethatt
heprogrammerdoesnotwantto
execut
e,r
athert
heprogr
ammerusesi ttoei
therexpl
ainablockofcodeor
toavoi
dtheexecut
ionofaspecif
icpar
tofcodewhi l
etest
ing.

Si
ngl
e-Li
neComment
s:
Towr
it
eacommentj
ustadda‘
#’att
hest
artoft
hel
i
ne

#Thi
sisa'
Singl
e-Li
neComment
'
pr
int
("
Thi
sisapr
intst
atement
."
)

Out
put
:

Thi
sisapr
intst
atement
.
.

Exampl
e3:

pr
int
("
Pyt
honPr
ogr
am"
)
#pr
int
("
Pyt
honPr
ogr
am"
)

Out
put
:

Py
thonPr
ogr
am

Mul
ti
-Li
neComment
s:
Towritemulti
-l
i
necomment
syoucanuse‘
#’ateachl
i
neory
oucanuset
he
mult
il
inest
ring.
Example1:Theuseof‘
#’

#I
twi
l
lexecut
eabl
ockofcodei
faspeci
fi
edcondi
ti
oni
str
ue.
#I
fthecodi
ti
oni
sfal
set
hani
twi
l
lexecut
eanot
herbl
ockofcode.
p=7
i
f(p>5)
:
pr
int
("
pisgr
eat
ert
han5.
")
el
se:
pr
int
("
pisnotgr
eat
ert
han5.
")

Out
put
:

pi
sgr
eat
ert
han5.

PythonVar iables
Var i
ablesar econt ai
nersthatst
oreinf
ormati
onthatcanbemanipulat
edand
referencedl aterbyt heprogr
ammerwi t
hint
hecode.
Inpy thon,thepr ogrammerdoesnotneedt odecl
arethevari
abl
etype
explicit
ly,wejustneedt oassi
gnthevaluet
othevari
able.
Exampl e
name="
Abhi
shek"#t
ypest
r
age=20 #t
ypei
nt
passed=Tr
ue #t
ypebool

I
tisalwaysadvi
sabl
etokeepv
ari
ablenamesdescr
ipt
iveandt
ofol
l
owaset
ofconvent
ionswhil
ecr
eati
ngvar
iabl
es:

 Vari
ablenamecanonl ycontainalpha-numeri
ccharact
ersand
underscor
es(A-z,
0-9,and_)
 Vari
ablenamemustst artwithaletterortheunder
scorechar
act
er.
 Vari
ablesarecasesensiti
ve.
 Vari
ablenamecannotst artwit
hanumber .

Exampl
e:
Col
or="
yel
l
ow" #v
ali
dvar
iabl
ename
cOl
or="
red" #v
ali
dvar
iabl
ename
_
col
or="
blue" #v
ali
dvar
iabl
ename

5col
or="
green" #i
nval
i
dvar
iabl
ename
$col
or="
orange"#i
nval
i
dvar
iabl
ename

Scopeofv
ari
abl
e:
Thescopeofthevari
abl
eistheareawi
thi
nwhicht
hev ari
abl
ehasbeen
creat
[Link]
sav ar
iabl
ecanei
therhav
ealocalscopeoragl
obal
scope.

Local
Var
iabl
e:

Alocalvari
abl
eiscr
eatedwi
thi
naf uncti
onandcanbeonl
yusedi
nsi
det
hat
f
[Link]
iabl
ehasalocalscope
i
cecr
eam ="
Vani
l
la" #gl
obal
var
iabl
e
deff
oods(
):
v
eget
abl
e="
Pot
ato" #l
ocal
var
iabl
e
f
rui
t="
Lichi
" #l
ocal
var
iabl
e
pr
int
(veget
abl
e+"i
sal
ocal
var
iabl
eval
ue.
")
pr
int
(i
cecr
eam +"i
sagl
obal
var
iabl
eval
ue.
")
pr
int
(fr
uit+"i
sal
ocal
var
iabl
eval
ue.
")

f
oods(
)

Out
put
:
Pot
atoi
sal
ocal
var
iabl
eval
ue.
Vani
l
lai
sagl
obal
var
iabl
eval
ue.
Li
chi
isal
ocal
var
iabl
eval
ue.

Gl
obal
Var
iabl
e:

Aglobal
var
iabl
eiscreat
edinthemainbodyoft
hecodeandcanbeused
any
wherewithi
[Link]
iabl
ehasaglobal
scope

Exampl
e:-

i
cecr
eam ="
Vani
l
la" #gl
obal
var
iabl
e
deff
oods(
):
v
eget
abl
e="
Pot
ato" #l
ocal
var
iabl
e
f
rui
t="
Lichi
" #l
ocal
var
iabl
e
pr
int
(veget
abl
e+"i
sal
ocal
var
iabl
eval
ue.
")

f
oods(
)
pr
int
(i
cecr
eam +"i
sagl
obal
var
iabl
eval
ue.
")
pr
int
(fr
uit+"i
sal
ocal
var
iabl
eval
ue.
")

Out
put
:-
Pot
atoi
sal
ocal
var
iabl
eval
ue.
Vani
l
lai
sagl
obal
var
iabl
eval
ue.

You might also like