0% found this document useful (0 votes)
4 views

Python Notes

The document provides an overview of the programming language 3t, developed in the late 1980s, which is an open-source, case-sensitive interpreted language. It discusses various data types, variables, operators, and functions within the language, highlighting its features such as being interactive and not requiring variable type declarations. Additionally, it covers the syntax for lists, tuples, sets, and dictionaries, along with examples of how to manipulate data and perform operations.

Uploaded by

jayjagu96
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)
4 views

Python Notes

The document provides an overview of the programming language 3t, developed in the late 1980s, which is an open-source, case-sensitive interpreted language. It discusses various data types, variables, operators, and functions within the language, highlighting its features such as being interactive and not requiring variable type declarations. Additionally, it covers the syntax for lists, tuples, sets, and dictionaries, along with examples of how to manipulate data and perform operations.

Uploaded by

jayjagu96
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
You are on page 1/ 23

3t is a

jeneral Poer and oct oritntad


langog
K 3t was deelaped ?n late 1980 Van rOSSum at
natforal esearch fnstittion
bGde
obampter Aene
4t is deRred
Such as
from pogag languages.
ABe ,modds smalt tal,Alqol-s8.
lqolG8
3t is open Sour
open scnpg langunge.
gt is a Case Sensitive larqaqe (d4f blw opper e louse
Cose leters).

Featuves of hon:
st is an intevpreted
Taterpeed pyaugngg
4 Jt is dn trteratie
?nterati ve
anglangage
K JE is postable

Salable jnteqaed and


Data
Data isthe Colledion ef 7qwfats is knaon as daa.
* Data is of ire tys
>1nteeflotag pot, chanakr data, bodlean data
k Processed data is Kroon as înfpralon.

Propam
n euecufon s
Kron as pocess.
* *charackr st ow ane
digta o to 1,Aabdsfom A to or

Token:

Srallest fnduvidual wnít in a poqyam is Krou as toker

tegod, 1åontfies, htead,opedtar


Vaviable:
3tis o data na) a
off mengog localfon.
locdton

are usrdefned to ken suh as


Vaable narnes,unctton names class nomeS struure

names and So on.

Rules fpr dertfers


R4t Car be a Conmtaton of lettrs n looer Case(oxy dit

Unders co re .
R Jt Cannol storb oîth a diqit.

Cannot be used as an fderbfers.

Carnd use gpecîal SprbolsItke 1# $+,ctct, dale

ao be used n fdentifer.

* Comas,or, b ank spaas are not presert

Iitecals 0 Constants:

x 4t isa fizad Value.

hee tupes

Vañatles:

dyaricay ped language. oe do not ned


to declare Variable type before usirg hem.
A VaRalbe 1s Ceated uohen oe qssign
q siqn a value to tfret
tfene.
ote
Vaß able names are Ca Se Sensiive

a=5
1-"hello

do not need to declare any vaiable type and (an


Varfables

ckange pe dif thoy hae ben set

Uote
tye of the VoRable oe arn you
you woant to know the

tyre(Vanakle namc)

uDant to Kroo rnemowg addies or la ation of the

se Can wse id ()funcion.

ralik Vavlble by dstig del damut


you Can dolte shde ca)

used to take fnpt fon he user.


pt fuelion is rre hed

Valable name nput (prog)


Note

To Conver t one data tpe to arolher dalatye ts thoonn.

functon txcepl?orn

nt () Corvets
Spit foc tion:
Thts mthod is
Converts ang data tige to fod.

Conver ts real runber tb lorples


Varrare =
nurmber. tzt = wclc

bool () any datrtype to bad Valu.


Convets
sty () (onver ts numeîc data pe to stiy Print (z)

Mze function

a- nt(inpat ('e nter a') This-function is

b- 9rt (irput ('erter b)) a: a,b,c = map

pirt (a+b) Note:


a= float () 2 ol be l.o
K prints any tetwo
4=flot (3:) f-fprmatted da

-float ("s) •when using an


braces are Y

Ex:
4t ts a oupt tunctor ued to rint.

piat(okjct ,Bepe cseperator stirg z erd <-end shi-)


message

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.

a abe= map (tnt,input'spltt)

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)

pnt f' You are tugri years ola")


name-ab'

Pít(5'3am inamey iarn agj Yeors old')


How
Vôtua
Byte Result
|Souc
eCornfler
Code e machine

Lfbrany
module

Note

because of
PuM (Python Vitual macline):

•Pthon virtual machine, ?sa platforrn deendnt langue

Data typ
fundamental daa hype (PRitive dala ype):
are uSed to Stoye
PRsive data types ay
-The Varioble Conains ony Shgle Value .
sirge Value.

Deived dala type ()Non piilive data ype:

•hese are re built upon he funcamental data


MPes and Gn
hold 6) morc
. multfple
The Vaableholds
valaes
multfple values
stuctures -

shudures

there e dtferent ypes deed


or Camle

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

Se Square brackats [ Jto defne a list

E a= o20,3aJ

Tugple:
bat-his is îrntable. means tts
A Tple fs sîoflar to list
eatisn.
elements Cannot be chanqed cafter

Fot deftigg a hupli se


t: az (to 20,20)
Set:
Setis an Unorde red collectton of elements that audorahcalg
YemoVes dulicate el oments
Set Vaßable Can only return
utque Values.
bYaces
Synta uie

rozen seli

.rozen set an muate Version ot


is a set. means its eemoat

Cavot be added (or)removed,

Sgilaa? use fomst ()


xf -frozenet fi, 3})

Diet:
•4t stores data în Key o d Vaue pats, ohere each

ndo: usebraee () to dere


person

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

Each element Ts an nte qeiYanges om o to 255


data -bhelo
pintl dota lo)

3tis am sômilar to a bytes object ,but ttiz mutade.

Splo bytearay)
soler t Saots Tndering and slicg

dala -byte aray (rss, 66,6 1)


data] G8

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

(2) Floor dinsion.


Aoat diyctor,: 4t retrns lottrapsnt'lalue. ()
Rt(sls) => (:0

Floor division )is sirlar to li?nc.


>20
pint (rol5o)
E:pint (slls)>1
1s an ztonent operator.

used to raise to operand to he port the ecad.


ff is
Vali=
Val= 3 pánt (valieral i) ?

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

Print Malb =aan d k)


B?t wise operaorst
these ofzratos
oferatos aye used to perfam operatons on bits.

Bitose and

Bitoise Xop A Bitwise NOT


Biote
Leftskft<
.A^B -ABABtA·B
letahift <<rey 20

hese opertors ane used to assiqn Values to Varables.


7az t 5 at=5

Kenbarshie operos:
hese cperators used to fa Sequene is reseñt i

kin it returns true.if the sified oect present in t


|ist.

+not în it vetuns te.?f-the Specifed e leent is not

Present în the list.

|E Sh1 -Hello wor ld'


D: List1 =[y2,34,5J
pint( list 1) n * True.
pint(8'n str) #

Et did1-{1: 'Gecks', 2 for',s:*Geks?

pirt (3not în dict 1) pint (s not fn dict 1)


(3

1deotiy opextor s are used -to Corpare the object:

is-re turnsTrue fbolh Vaf ab les ye fers Same memo

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)

C-a print (a1 is s2)


Si Vhello ioorld"

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

kit is used -o de fne block ofCode .


tst tells thepfhn ntyretze that agop of sl alenents belang
to Specifie block.
ih
he Sare level of xe
îndentation Bale (onsider
k All statemern's Same block,

*1 is achieved ueing tohtte spaæs (Tab),d the befin oing

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:

pint (messaq stäpo)


-Values this method retuns a vieo obe lhat obi
Conlains -lhe Values of adictay as a list.

Ea' Car

brand'; "fordy
"motor':'Mustang,
Year :1961

2= (ar. Voues()
Pint ()

Sorted :This tunctin vens a Sorled tist of he Spechje

iterable object

>You Can Specify ascending(otdes cendng nder, by deful

|
it reliarns orderi
n a'serding

Sortedileable,Key key, reverse, °Taue False)

a - (,,
=) 12)
Sorted a)
pint
-Totersectioo (): Thismelho reisns a set thol Colaos

blo tooo) me ses.


S0: st:Rnesection (sei,Set2. , et)
setl - ,2,3
Set 2 - 2, 3,43
sets = hte sectioo ti,st)
Pint(st )
Set3 -(set1&seta)
Print(set a)
round c: this -uncion eturns the floling psint, ierourded
nan o de Emas.
Version, Df urober oith specied
Assocvy:
he sane y
*whenever too er more operabs have

ter asotkny defres the orer of operation

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

Sortedileable, key key, reverse


a- (,1,12)
° The False )
7 Sorteda
pint a)
.nteiSection ():This melho reuins a set thal Contais

ho tooo) màe sets.

Syn: Set.ntesection (seti,Setz et)


Sel1 2,3{

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

f-else (Contains -loo bloc Ks ie, tue False bock)

(3) elf

Snple if Sytau: if condtton:


statements

ifete 4 Condition:
statements
else:
stae ments

(.uonte a ryhon progosto find given num ber is p


number ne nmber.

a=fnt Bnputo)
if a zo!

piot ('Positive

else :

Q.woite a Pghon prgarm to check ofen YearisT


Yeatînt (rpito)

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)

•ondrtional Conlio statererts


Decfdirgthe oideroecection
:
do statemerts based na
Conditions

)There

D
are three

f-else (Cotains too


types of

Srple f (ortains one


odiors
block

bloc Ks
ie
ie
tue
tue
bock)

L False bok)

FSrple if Siaa: t condtion :


staternants

ifelse

.
4 Conaition:
Statemests
else:
State nents

oite a pyfon pogorn to nd fren number is poi


nurmbey
icgotie niber.
a=Ant Gnpsto)
if a vo
pot ("Poitive)
else:

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

p. Ttnd the larqest Value ot any fou thtegrs


abedialmoptr rapttnts

a- înt(input)
b int(inp)
c-nt (nto)
deiatinpt )
if asb and azc and a>d!
pint as qreate st')

elff ba ard byC and brd:

ealest")

lif ca and c zb and cdi

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

tof Varame in sequence Tange C) i

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:

Targ mehod uas hree ipes of paarnetexe


3 start ?
(3) Stop
()step
snla:

)Rihon use Yange meied d fn thee ways

Yang (stavt, stop)

a ronat (atat,sbp,slep)
Nofe:
Plparamelers nmust be htegers
All parame ters an be te nt a)-e o.

for i n varg ():


0,13
slerterneots ,

(obreak
) Conlinue

te

print ()

break

break

int (1)

d (orrue oith the et 1est

it=1
If13
Contiu
prt)
Nested loop :
A loop Pnstde anothe loop is Kn oon asneiled n

foy Vav n Seqi


statements
stalerment S

ole
for in range (1,0:

for j in rang (i9):


Print'
print (f'*)

Shape attibute
:
the number of elernerts n tach
he
shape of an amy is

dimens on
Note:
an altibule Called shape that rib

NumP an rays have


hau
a tugple oth edeh ndee
haing the noof Corespandhy

elements

E!

pat (ara stae)

cinen Ts.
Shape

You might also like