Docsity

Data Handling in Python, Lecture notes of Computer science

Toggle sidebar
bg1
Date
21/7/19,
Page
DATA HANDLING
lo handle data we must know wlnat i
dataPata
is_a
Value oset
ot values.
Pdthonhas many versicns
and
Veriaus
nterdaces ike Pathan shellYdhan
SCript,#hoconda,
Spder,Jupger)
DataHPes
Theupe cdata
VVIM
and associadedoeerationsHor
handling
t
iscalled
datatupes.
There ore
vaiousupes otdeta tupes
Supposied bPthonwhich depends ondhe value
cta_
stetement placed on ia-hand-sideatitPhehSuppet
builtin_core doda ypes Nuloersin,iloat,complex
ƄjSttina iList luplePictioxna
oNumbers
Anuberdataupesase usedto storenumeric
vaues
in
Pthon henumbersiPthonhawe llawing
coredata
ypes=
Indeeis
ined integers
iocleaniegers
co loating
poit
data
Comalex numbers
(a eers
Te tegels arewhole numloerssuchas 12,3,ete
hese abershowe oAachonal
pasds.dnlegers
are
pf3
pf4
pf5
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Data Handling in Python and more Lecture notes Computer science in PDF only on Docsity!

Date

Page

DATA HANDLING

lo (^) handle data^ we^ must know^

wlnat idataPatais_a

Value oset

ot values.Pdthonhas many

versicnsand

Veriaus

nterdaces

ike Pathan shellYdhan

SCript,#hoconda

Spder,Jupger)

DataHPes

Theupe c data

VVIM

and associaded

oeerationsHorhandling

t

iscalled

data

tupes.

There (^) orevaiousupes otdeta^ tupes

Supposied bPthon

which depends

on dhe valuecta_

stetement (^) placed on ia-hand-sideatitPhehSuppet

builtin_core doda ypes Nuloersiniloat,complex ,

ƄjSttina i

List luplePictioxna

oNumbers

A nuberdataupes

ase used

to

store numericvauesin

Pthon (^) he numbers i (^) Pthonhawe llawingcoredata

ypes=

Indeeis

ined integers

iocleaniegers

co loating

poitdata

Comalex numbers

(a eers

Te (^) tegels are

whole numloerssuch

as (^) 12,3,ete

hese abershowe^ oAachonal

pasds.dnlegersare

lAsSMAte

Date

Page

Tepres.entedinPthonby nuericvaluesuithnoolecima

point (^) lhe integersCan loe posihiveor neqadiveas well

denotedby o TespectivelyThealasenceotanySigh

in_aMumaer sepres.emsthenunnbesispositiue.

ƤiBoolean

These represemthe ruthvalue Irueand Falseas beolean

date Re isaSub-tupear^ ideaers.

hevehues likeOae

repiesentsthelbcoleanvalues

userUser pesbool^ Co)he^ autputuillbe

cle andtypes

beal heoutput wlbe hoe The valuesdtue_ondtalsecan

alselaepe^

cast hroughs rtakse)andstrtrue)intostring-

Lalsecas^ Truetesp2cvely

caloodinqpoi nuwber

A nmlaerhoinqtioactianalpactisa^ Hoatiua

poitunberIhe

uwwlaer

Sianals

iisel aS oceiafoinihumberandhatan

ieerwhent

has (^) pain int.An inteercanalsohe

representedasHoa^ pon^ numbek,

as iO Can be represente

as0.O^ Hloctinqpoindnumaers

can be tepresenteNinuo

r s dtacionaldossaand i,eponent_netahon.

headvaogect^ using^ ocdhng^

polndaubersfs-had

aenesdes numaers beheenanyo cansecuthv.einteger_nundoes

floatinpointnumber^ con^

haue 15 digts_^ precision

OComplex number

Pheni6a versatileongnge

which suppordsmany numeric

Hwees one o tae isComplexnulaersAcoplexnumlberis

inhe SoE oAtjwhere^ tepresehdshesauare

tootot

AnĆŗmlberwhi.chch isimHhe datmot 3.at2.4jS.Gis

ea pastand 24jisimaginaypark

elassmate

Date

Page

CaList

A listn Prthon tepresems (^) a listot (^) comna sepakaded

values_ot

data hupe oetween Squaie locachetsl

e ,5,9,11,1GI

La,e,i,o,

l5,2,Neha,Pankai,o07J

Likeany othervalaesalistdo^

have a variadletaea

a 0, 20,30,Ao,60,100o

La user^ wat^ o

accessHems c^ alist.kor

e

Fitalol)}

Jtches/accessesirst

valuedro lista

prit(alo)^

Haccessesthethird

valueron lista

ptintCc)21pints

al-Ahevalues

ot list

uples

heyalueso^ upelist

areautahle,

e itcanbe^ cdacnaed^

Thisueans

onecon^ chan e,add os_oleleie

tems ot^ lis^

here isa^ conce

ptcalled

huplesinwich

he lstscannetbe

chanAed,ie.he

tems_asend

onoditiable.luples

aserepreseat.ed

asisto_comc^

Sepatodedvalues

o onydatadype

withindhe parerthe

sis).

PE1,2,3,

1,5,6)

4 (90,

32,A5,

Dichonaries

Diotisno

dokdlupe isangtherdehuse

inPpthanshat^

he dicdioncr

ison unosderedset^

aCOaaSepasaded.

key valuepair^

hin

oco ce^ Lwth^ dhe sequisement

thotwithindhe dictianary

hotwokeus

elAsSMAte

Date

Page.

Can lae

same

fetesd:a:1e':2,2:3,'o:4'?:

DictionayyaJialuleLKey

ptiatCo[a)_

Prthon has lwadatadypes

APrimveDadaype (^) Cnunabers,String

2CallectianDatadupe lasl,Tuple,Set,Pichionony)

Data

Iypes

PrimtiveTDda (^) lupe Collection

Patalype

String Number^ LisTuple Set (^) Dictiona

int float (^) Complex

Mutahle_ond mmnutalale Data

lype

aMudable (^) Dadaupe

hesetaechangeaaleJndhe

Some emos addiess,new

value

canbe stoted Eg List,Sei,Dictionay

lasSMate

Date

Page

inReladiona Opencdors:Relcdiona

operctossCompase^ thevaluesH

edherrehurns lrveo^

talkeaccosdtngodhecondition

Operados Nane^

SudaxPestla:lG,E42)

Careaderthan

FdseA

lessthon

Irueil

false

-/ Nteual

ve

FalseA Carectertnanosequ o (^) zE

Lessthancrequal^ Iueal

aLogic.alOperudorsilogicaloperadorsperhotnLagicalAND,Logical

OR and legiradNo1opercdorsa

OjperdorH^ Des.cripion^ Szutax

Logica (^) AND:ueibaththe operandsasetrue

Logica) oR:Irueietherorheopemnds isAruelaacy

and

no iloqica)NOT:Trueiopercndisdalse

Exanpleso Logiead Opercdor

The and_operdor:heand operator works inwouaus

a (^) Pelad.onal

exprs.ssionsascpesands

b.Numbers os

Sinasor lists

asaperands

a.Pelodionalexp1essions0saperonds

elassmAte

Date

Page

and (^) y

false (^) Falae false

False

Irue false

Troe false^

false

Irve Arue rue

(^72) 6> 8 and 723

fadie

(4==4)and (7==)

Irwe

h.Numhess orStrin^ sos^ lisisas^ operands

anexpresSion

XandY,it

isoperanod has^

alseyalue,thenrehrn

instopeiandx

asasesLt,athewise

JetusnsY

ond

dse S.lse

0and 6

Selke

drve

ue se

a2 and^ n^

dve ue

and c^ +9>^

Hand opercorwilHest

Haesecand^ operand cnly

Hithesi opRiand isce,otherwiselanares

1, even iHhesegandopercodicutang=

Falke

he os^ operocto^

lhe0s opercor

worhs in_

wo qs 0

a.Relationaexp essionS

as opemnds.

b Numbers^ or

Stoingsor lvdsasoperandĆ”.

elasSMAtee

Date

Page

9or Ct>5oroperckoswilldesthesecondoperandonlyihe

True #stopesandis\alse,iherwiteqnaiesĆ ,even

he (^) Secondopesond 1 NGnA-

henotoperodori

notG

false

no O

Irve

Fadser

Cheined Coimporisan^ Oerdossi

4<523 isequivclent

b >>>4<5and^53

Irve

Bdwise Opercdors^ B

hwise operdossoctson^ laisOnd^ jacosns

ta^ bit

operodion

Operadion DeScription^

Syntax

iwiseAND

Ditwise0R

BwiseNOT

BdwisexOR

A

Bihwisesi^

shit

13daiselel

shit

lASSMAte

Date.

Page

(yAssignmem OperedonsAssignmertoperdorS_areusecl assiqn

valuesdtahe^ varialbles

Operatar

Descriprtion Syntax

Hssignalueot^ riqhlsideotexpression

do le iside

0pernd

AddAnd Add iaht.sideoperondwthleHsideoperandat=b

andthenbassignb leltaperand

SubttacdAnd:Sulhtactriahaperand ram letopesound

and Haen asian letopernal

M.tHl And:lukiplysightopetendwithleltaperencd ab

andthenaSsiqntoleltaperand.. a=a*lb

DivideAnd:videle toperanolwHiaodopchond ansda/h

hen cssigntoletapekes aa/h

Madulus Prd lakesmadulus usingletand tghtoperandraZ=b

ond aienecutole ope rmna.

DivideClo)AND:ivideleltojseroanolithrieht

opecondand-thenassignthevalueCliaac)o leH

asah

La_ll=b

operond.

EzponevhAND Colcoladeiespeanent(rasepaes)vodve a*ih

wsina opetondsGncd asslenvalueto hatnesc =a„*b

PerdoimsBiuseOR onoperandlsGnd assiqnvaluetoalh

letoperond.

Perosms BihwiseAND on

opesands_Godasslenalue-b (^) la&b

letopecond

Q=allh

A Pecorns LiuiceXOR (^) onoperand.sand (^) ausignvalueto

letoperonad

fesosms Bruisergh.shiHonopefandsand assign

yalue (^) azz=b_

o letoperand

alassMAte

Date

Page

USed pAest whether^ avalue_arvociable

isina Sequence.

ivalueistound^

inhesequence

not in Iruevalueisnod^ oundintheseqvence

Example

let

a:Diaitandia

a,

4:

pr'i p'in)

pra Dighalhotin)

print (^) in

peintC (^) h

Oud put

Irve

rve

felse

Irue

false

Opercten Precedenceand Associativithui

ƤOperctorPrecedence describesheorderin which

oyeradionsare (^) pertormeduhenan expressioniseyalucdel

Opersdos (^) uthligherprecedence perhocnheoperatianfus

inOoeretor Asso.ciadtivhyWhenexer duo (^) os

mose aperabrshae

he (^) same (^) precesencehen associativihydeinestheorder

operations

alassMatee

Date

Page

Expressi.ons

Anadom isSonmething^ hatlaasaValve.

Jdlentiiess,esols

striaslisdsdplesdictianadsiesalareados

Hn expiessioniaPictaanis_anuvali_combinaction

o cpercaOD

and adoas Hn exjoreSionkmau_comjaace_atone

ororeOpeĆ­odioas

There oreourupesotexp£essicns

Hrihueticexjoression

aRelaticnaeiessian

3Lagica expressioa

ASinaxoression

Ardametiq expreisicons^

Luhen

Acthmetic expressionsmvalues

nobes (inteqess,

Aoat conalex

Walve S)andarthwaetiu

operotors&

btc2-

als O)*-

dinRelotiona^ expressions

allae

An expeSsion

havinglidefals

acd/or_yarjables

of_anyvalid

clata

pe and^ relotional

opefotor_COn

e reles.ced.Qs

relaianalexpf

essian.

a>b

oAical expressicns

An expressio^

havinalitexo^

ondor Vasiablesot any

valioloadatyepeL

n loko)

opeatoisO

logicalexpiession

candnat

elassmate

Date

Page

5)sin

O

his dunctioncetunshesineor csgument (^) passed

ta

nacath: sin(O0) 1

G)cOs

This dunctioneusnsthe cosine ot (^) otgnuenieassed

Eg methcaslo)^

1

Han

hisduncdionIeurnsdhe angentot asAumenipass.ed

amccth.danA5)

S

S)expO

Thisduncion returnsthenadora loaarthaaice raisetopawer

of enipasSedalad

Ea=mazth,exp

(2)Se

The loaAouncfioncehrnS^ he

oasei0logasithauicvaluetor

MDnbe

Ea math.log

CA) E

10)c.b)

Thic undioncehrnshealaSaludevolueoiaenialaerpassed

mccth. talbs(2.0)92.

uatun

mdh.dahs2.0)2.

CCAEhabia

ride donthecorseSpondiugPythanexprecsichtache

ollosuigmcche^ aacicoexpĆ­essionS

elAsSMAt

Date

Page

  1. (^) 2-ue d

A)e-

1 mcth^ Sqrta„2tb*

CX„2)

Mgth.Sqt

dtiapow a,2)^ tmatih.

pow( b,2)tmth.joowCc,2))

-ymathexpl2y+A

A)mahichs(moth.exp(2)-)

CaA

p q/madh^ potu(rAs),

A)

Qderhhepes_otyaluesgivexhelow

3 3 13.0,1313, L3,13,21,(3,3,2)

3 ideger

3j2Colex

13.0 loct is

13> (^) shring

l3,13,

is

(3,13,2)Auple

QWhot wiletheoutpu

ot dollowing

pritClen.CstA7//

A)_

printlenCstr

(17/4))

o/P A^422