0 ratings0% found this document useful (0 votes) 47 views39 pagesPython Unit1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
ne programing Language TE wa. created
by Guide Yan Rossum and released im 1191 at "CHI"
[centrum Wiskunde 4 anformoclica] Netherhand.
ose, High level prograramning
fyth
‘ Py thon is a General frp
Language -
+ Python so dynamic
(axa: Oe
= Simple £ tasy +0 Leet
- Platform Trelependent
- Pree 4 Open Source, .
7 Totex preted. G bytecode ~Compi led)
— Rich Library Support
— Embeddable 4 extensible
— Portable
= Robust.
(ole tyiioa © Wal)
ee ee
+ Web Framework and applications
* GUL - based desktop Applications.
‘ Graphic. clesign , image processing appli cections,, Games
and sient (fe |eondultore applications.
* Machine Leersring. i frstiticial. Intelligence, Neural Nehwo
* Dala Science, Data Visualization. :
© Thteenet shings (ToT) "
+ Database, clevelopment .
© scanned with OKEN ScannerVudhon vs Ober
ot Tnclude. < stetionhy
int main()
printf (" Hello, World. | \n");
relurnos
ay
print (" Hello, World \")
J
publie class HelloWorld ¢
ublic static void main
(shing Tl args) {
system. outs pritln C"Hello,
3 world |");
3
Firok progran in Python:
7a fe
jC
print (" Hello, world |")
“Thput from user in Pythons
or Taking input suom User,
hame = input (" Entew owe name")
print (’ "Hello," + name )
print Cpe Cname)) #Exeaue
Entex. yowe name Python
Hello , Python
. , Ry defhutt
© scanned with OKEN ScannerNJ
st Fyeace
Enteow a Tumber? [o
jo
Type Frror .
Wyre Error; must he atr, Not ink.
num = int ( input(" Ente a numbee:") )
print ( num)
paint Chere (Mum))
num =num+2
print (num)
. Note: Aloat , bool
\ nies Heats Ba
eciinal
Value
\o.0
120
tt Exeute
Entec a number: lo
= lo
[>
12
F Flocet
bool
© scanned with OKEN Scannerabba it I}
Nasdabla in, Fython
fata vabues,
Vastiabe, ase, containers ir.
J
Creating. vasiables
thon has no command for cleclaxing a vasdable ,
A Vaniable is cxeated, the moment we first sign
Q value do iz,
1. X=5
t" “Sohn”
int (>) 4E output
pt (4) Ss
John
7 Sor do not need 4o be declared with any
Aca duce and can even change i
They shave been set. é “are ape
C4. we ar xis of pe ink
Total at x it of ape kr
print) ae ouput
Sal!
Castin J
ry T4 we want +o speci the data “tHpe of wu
Vosuiable, this Can be done with Casting.
é 4 x= str (3)
= int (3)
Z= loot (3)
wink (x) + oubut
‘ '3) 3
print ap 7
pant (2) do
© scanned with OKEN ScannerGet the Tybe @
can get the data type of a vasiable with the
sanction.
type
0-9 25S
d x = "ah" output
ink (type Cx))
pire (ype) K clays 'atr'>
Single or Double Quotes ?
+ Qing Vasdiables can be declared, either by using single
oy double quotes:
eq x= "John"
print (>)
SF double quotes axe the 2ame as single quotes.
x= ‘ohn’
paint &
se output John
7 Sohn
Case - Sensitive
“Vasdable Name, ce Care - gencitive
oF Qe4
d Az "Sally"
print (a) oF ouput fu
pant (4) ¢
© scanned with OKEN Scannerby {hon = Vasdable Names
© A vasiabe can have a short name (like 9c and 1)
OF & Move desesdblive nome (age, carneme, total schon)
© Rules:
"A vosdable name must gtaxt with a Lettee ov the
Undeescere charactee-
A vaxiable name cannot stout wrth @ number,
"A \osiable name
can onl contain alpha. —numesj
Characters and unclesscores (A-z, 0-4 and—)
* Vaiablehames axe, Case - sensitive Cage, Age ang
AGE ase three, different vasiiables)
A yastiable name cannot be. ant o the python
Keywords
Examples-
Legal Vastable names:
myvare= “John”
my —Vase= 'Nohn®
Tegal vasiable names
amypVarw= "John"
eVUe = "John
= my-vas= "John" me Vae= "John"
myvAaR = "Cohn"
myvox2= "John"
Multl Words Vasdable. Names
+ Vasdable Names with move than one word can be
Aitti abt to read,
+ Te Axe geyeread, Aechniques we can use to make,
them more readable:
: Casnel we
Each word, except the first Stosete Ut °
, a
minis Hh a capital
ty Vautiabletlame = "Tohn"
© scanned with OKEN ScannerVosral Case
Fach word atasds with a capital Dettoes
MuVauiableName = "John
Snake Case
Each word is separated bp an underscore cha
‘ TO Chee
M4-Vatuable_ name “Tohn'
Hython Vauiables- Aasan Niuttibie Yabuns
Many values +o Multible vasdables :
« Python allows us to assign values to multiple vardabk
in one Line:
Example:
BYZ = "orange", "Banana" | "cher"
print (x)
print CY) ouput Orange
paint (z) Banana,
4 Cher
One Value 4o Multiple Vasiables .
* we Can assign 4he same, Value +o muldtple,
Vastiables in” one Dine:
Examples
M=Y4=Ze= "ore "
pants a
maint (4) tt
Eaekce) ouput
Oran
*
OFange.
ora ne.
© scanned with OKEN Scannera ar
¥ Unpack a ollect1on
| ; : :
TP we hve aq Collectoon of values ina thst,
uple ete.
: Pythen allows Us 4o extract the valuer into vasdables,
This is called, Lanpaing
example: i 7
uit = [7 apple, *benara’, "Chere ]
x, yz > fiutts
int (2)
; oe outpe
print (4) apple
print @ nan
Cherry ‘
The patton print function as oHen used to output
Yasdabler
ea. ve "python ty Qwesome"
paint (yy
4 out
Python is Quwesome,
« In +he print (© Function, we ouput
Atbarated. bt Q Comma:
eq: Xe % Python"
pe ist
Z=" auresome"
print (uy)
multiple variates
fF output : Python +b, awesome
© scanned with OKEN Scannere w in also uge the of operator to Oulpeat
muldiNe vasdables:
cag, X= " Python"
toyed
suprat
Z = "dusesome" ap
futhon ts Cwetor
snk (x4y+ez tho
prt Cxagte)
l
Note:
he space characte. Abtese "Python" ane 0 is%
he tesutt would be "ty thonis awe some
} Op
© for numbew, , he ct characker, works as @
mathematical, Operator:
eq.
q xyes
«lo 4 output
point ies +4) is
© In he print) Function , when we +o Combine
A sting and @ numbee wth the ch, Operators
pythen will gi US an errors
eq. X25
4 4e “doh” +f outpeck
prink (x +4) Type tor + u ee opean
ype ca) foo +3 tint! And ‘abe
+The best way Ao output multiple yasdables fn the
pinto funcon is to separate them with Commas,
which even stupport ditfewent data. Type:
eg
xs
= "John"
prink CY)
4 oulpur 5 John
© scanned with OKEN Scanner+ Built-in Date T pes
© VYawables can gore data of diferent ‘ype and di. flee
Aypes can do diteuent things :
Q@ ‘Text Types ar (*y efoutt]
é Numexic pes: int, flak, Complex
© Sequence Typos: Lick, tuple, ange
@ Mabbing Type + click
6 Sek Types: sek, » Prozenseé
@® Boolean ‘Types bool ‘
fe) Bin ‘pes: bytes, bytearay » mee
None ‘Type: Nonelype
Getting he Date. Type
: et the date e. object using. the
“te sthetion. “ ot *t t
°y Sane e CX)
Pink Copp ) ar output < class | int! >
Setting the Data. Type
Ce
e In peer, the data
value +o a, vasdable:
ype ts get when we assign @
cn)? ol
® hin cptlo pale ae ouctput Hello World
part (type cn) 4Clags ‘ste! >
(2) int
F=20
ink C7 ar odput 20
ink x) é
rin ype”)
© scanned with OKEN Scanner“)
Ye-putpat 20
print (2 xclass ‘floats |
sa age a
r= ae output TF
print (x) r «Class tcomplex!>
rink (
i. ro
paint (4ype"))
t
['apple", "banana’, "cherry"]
print (x) ae ocetpuet:
print Care cx) Tepe’, ‘banana’, 'cherry']
4ubie7 =~ zclass thist
x=( " apple’, ” bara”, " cherry")
pint oO ay outpul
pint (Ayr >) (‘apply "banana, 'e her! )
class ‘suple’>
Bange
xz range(6) ¢ te owt ;
aint (X) yrange (6
pint C4ype 0) ess range! >
dict? *
x= F"mame" s "Sohn", * age": 36}
int (£)
print (HERS cx) at output
{iname! 'Sohn!, tage’ : 36}
ont A Class 'etict'>
ae aatae,
xe 7" apple’, “banana”, “cherra"4
aint (©) +E output
pint (ype?) L'apple!, ‘cheny!, | banana’ j
Aclass 'set!>
© scanned with OKEN Scanner: G
xe drozenget( £ "apple, " banana", "cherry" )
punto
paint ($ype0X) =p output
ir jae {icherrg: apple! ,banarat
my ; "
can ¢ bod) Xclass ‘frozenset! >
a Y= Wu
print ae ocetpect
pant Caype 9 True
KClass, "bool! >
aa urorre
fa) tor
“ye b" | “te owt
fink CX ;
aah mm pb’ Hello!
print CY ») class "byte?
mutable
@ bylearra i? :
= byt ig ae output
a ) wt (' \x00\x00\x oo\xoa\x
pant cL) by
paint (44pe 2) clase ‘bytearray'>
ix ya i
® _ memorpview 7 eo Ont te tke
a= memory ( bytes (5)) tations prt athes ea
int (x bytearray often nvelye,
int (2) sroutput "creating neu’ ohgects
print (4ype09) A memory. ak 0x 00B0RFADY
is) Nonetype o's dol ahak represents the
€ owe Wage qhsonce. Ch a Value
int CO) ae outpat
pant Lipeeay Wone
© scanned with OKEN ScannerWybecasting. in Ty thon
| (
© when performing. OPexations on data in Python » there are,
Siluations whore. we a needs to Comyort “the data type
4 & Voutiable dnto He destred. type:
ods © se Casting. | Type Conversion
Methods of HP a ne | i F maton
/
Fp, - eee :
Ty fe Castit aSU
ipeeiy He oot
Conversion of data Conversion of data types
‘types 4s done ig done, by the user
auctomatt calle bt 9
Piython
Fenplicit Type Casting
6 The dala *ypes ‘in Python have an order ‘in which hep
Que “handled « ‘
cohen working wth vasdables of diferent dato. *4pes,
the Ayton a eter customad cally Conwescts OL date
2 inte Higher order date bapes this J done to
prevent deta dose.
Goohes
pri (dala ye a! fe)
ine data type of B! type)
mint data type ofc, types)
d=ath
© scanned with OKEN Scannerprint ("the value of ds’)
print (‘data type of d:', \ype ())
&= Wh
pant C' the value of @:5 e)
pert (tdata “ype of e:; “re cer)
4 oul pad
dala ar of a:
Atri
tye c string jy
© scanned with OKEN ScannerYu -~ Jo
7 stmage in pythea are
surrounded be eiihen, Sigple
Potati sn marks or clouble. protadion marks
" .
hello’ is the «game as hello’
is ath
e4 rink (Hells!) 4 Hello
. pint C'Hello!) Hello
Quotes inside Quotes
e print CTs alright »)
print ("He cs Called. ‘Sehnng! )
print (* He is caved " Python" ')
4e Th alr
He Js called ‘Sohn
He ts called. "Python"
Assign sting Ao a. Vase,
Assigning a shing tdavasdable ds done with the
name followed by an -eqpal ign and the abing:
yastiable
eg. a= "Hello"
d print i) te Hello
Multifine Str pile laude. qpotes or
tiple single quotes [7 *]
ge "" Never gonna gee a Bt "I ve
Never gonna tet a own
print (a)
Oulputs Never gonna. aoe yeu up
Neveu c let tee clown -
© scanned with OKEN Scannering |
P characters by using. the slice .cunt
; ot . “Atty
' b index and the end index, sebarated
by a cols, to relusn a pare ofthe string
| J
Pa. Get the character, from pesition ato posilten F (hotine
ba 4 rl!
print ( bL 2S, Noles— The Fixst character, |
+ Ilo, W ; fas, index od
slice. Crom the start
o By leaving out he ake index, the range cil staset Ot the!
fost characters
ea- Get the characte: wom si i
§ 8 (rot included)
o, world!"
Slice To the End
© By feaving out the end ‘index, The range will ye Lo the end:
eg. Set re characlers teem sition 2 and altthe
wor te the ond’: P
b = "Hello, world |”
paint ( bl2:])
te No, world}
Nagective Indexing
2 PS ee cee
+ Use Negative ‘indexes to stare the alice Bsom the end
% athe arsing?
e4- Get “he characters:
from: “o® in “werldy” ( Position -s)
© scanned with OKEN ScannerTo, but not nel i Here eee == 6
not meudeds a IN © Worldly ¢ Pasition -2):
(Ww)
|
| he he vesutt 4 dhe “ell n4
Ke ‘welcome!
print (18:53)
« Icome
«Come
«com
NGS
Ayton _ medi
* Python os a sez af built
on stvings.
in metheds that we can use
upper Case.
&4 ame upper pnethod rewwsns the string 10 appre Case 4
ae" Hello, world"
paint Cas upbecO)
se HELLO, WORLD!
Lower Case
eq The lower method returns the string Tin lower Case:
a= "Hello, world!"
pint (a: lower)
te hello, world
Bemoye whitesseee
+ hides pace js the sbace, before. and Jor alee fhe actual
text and vou often we uxnt - remore this space’
© scanned with OKEN Scannereq Tk MPO, method remove any whitespace. from the,
beginning or dhe ends
Q=" Helio, world) "
texbtbO)
Se Hello, world!
Replace string.
9) THe replaced. method replaces a shing
Qe “Hello, world!
print (aereplace (™H", "T"))
4e Jello, World!
Split string.
Te. abiagy method returns a isk where the feyk between
the specified. gebarater becoma the List items.
ee The sptit GQ method aptits ane shving into Substeings if
‘ke Finds ‘nstances of Ane aeparakors
a= “Helle, worldl!
print Ca apt (15"))
He L'Hello!, ' world {"]
with etnother Shing:
Pylronc sting Concatenation
« ging, concatenation.
pgcie Horizontal fab CTA®)
tate "Hello |+ World. |"
peing(ext)
ste Hello. World!
© \b Backs pace
xk = "Hello \bworld"”
print Cht)
fF HelloWorld |
(7) \o00 ctl value
xk M\HIO\ 4s \54\ 54\ 53"
print (4xb))
AE Hello
© scanned with OKEN ScannerLyk vycan\pes\n6c\s6e OF”
print (xk)
4 culpa: Hello
ay \t fom feed
go “hello world"
pont (s)
+t hellowe (d
*T) \ —s mockwad 4 newline ignored
, Bets sine boil, met foclude \ backblaghes or qaoline
_ Chaxa de,
peint(s) *
(i) \a > pAscit bell (BEL) produce @ beep
: \ sound ov @ visual
s='Hello\e +E hello notification on
pant (Ss) : inal}
@ W.> see Vertical Tob Ww)
s Hee world" 4 yptioworid
pn Cs.
© scanned with OKEN ScannerLython- string methos's,
Python has q get of built-in methods that We can Use on
strings.
Notes All aking methods felurn new values. They. do not cha,
the. original airing.
Ge
Method Desert pion
Capitalize) Conyexts the fisst character, to Upper case]
Cosefold C) Convetg, ating into lowes Case
Center C) Returns a centered, ating
Count C) Returns the numbex of Himes a specified
value occurs in a arring-
encodec) Returns an encoded. version of the ating
end ywisth C) Returng true bf the atsing ends wrth the |
specified value
exbandtabsc ) gets the tab size of the shine?
fine C) Seasches the using for a. spedfied. value
Gnd weluyns the” position Of where H was
fend
foumat( ) Posmat specified, values in a hing
Yoomak-mapc) | fosnats Specified values in a. ateing
indexc) Seaxches the ating fora specified value
an iti i
a ‘the position of whexe it was
isalnumc) Returns True if all chaadoa y i
Axe abbhanumedo, a a
ieabphac) — |Retuxns True. iP alt ch i i
P ee P Chawcten, in the abing
Tgascitc) Rotusns True TF all chavactes In the,
Sty ing OuE Ascii Characles,.
© scanned with OKEN Scanneriodecimall) — Rehurng “ue if all characteny fh fhe abving come
decimal
tedigit
i the stsing ane
ate taieitierd = Sit oe
Isidentizteet) Reluns True if she Shing Te an | Lentifion
iglowert) Returns hue if all characiecs in the asing axe
| pwern case. d
wsnrumedcd | Returns True rf all Chsockees inthe skiing aut mumente
isprintable Retusns Tue Jal Charades 4 dhe shi ae
Printeible.
‘sepace) | Returrs Teue if all characte in the string ane
wotittespaces.
isttleQ) ae if the sing follows the rules of @
Teuppeo
4oinc) [Soins the elements ef an Hexable to -the end of the
shsing
tO | Returns Deke gust feck vetwion of the. string .
Returns True if all Characters inthe. bing are Upper case
Tower) | Convests a seeing into lowe cose
IsteibC) | Returns a lePt trim yession of the string
makestransc) | Relurns Q4ranslation fable fo be Wed fr translations
HH @ diple whee the string. fe pated Thfo three,
partition’) | Rehns ae tis Pas
replaced) [Rejumns a ataing hoe a specified value GB veplaced
wrth a apedHfied value.
nd) | Searches the atsing Tov a spectfied vallue@ And reheng
Ahe last position of where it was found +
Findexc) | Seaseches dhe shring fora. Abeci fied vyadue and returns
the last position TP ohoee it was found.
rust Returns a sdaghe fuotifie voxion of the sting
Tpasditiont) Returns A table where the abving 1s pucted into
aeeae three ports. ¢ tf
rsplit¢) splits, the sing at the specified. epurcator and
tabrent a Aga
© scanned with OKEN ScannerInte a siti Sannin
babipO
Returns a right fim yeaion of the shirg .
apt O
aplittinesc)
Stuckywithd)
Splits the ming ak -the Specl fied, Atharator and
relung a Oigk-
gplits the ahing at tine breaks and seetusny
Q Dist.
Relums true if the sting atarts with the
specified. yatue- :
sip 0)
Rettuns a tvimmed. veaion of the suing
| Swapeased) | Swapcares , Ae wercore become uppeecase and :
+itle ©) Converts the first character: a each word to
upper case
translatet) | Returns O translated. susdng.
Upp] Convents a ebscing Tne uppercase
zac) | Pill, the bag th & a specified. numbex. of 0
values Ot +he
eginning
© scanned with OKEN ScannerPuthon Ponlear 1
+ Qooleans represent one, of wo valuess True ov fale
: od
4 print (loa) + True
Print (lo==4) false
print (10<9) false
shen we tun a. cendition in an if aintement, Python
retuws True or False: Fe
eq O=200
b=33
if bras
paint ("b ds greatex than a")
else:
paint ("b ds not great ex than a")
dk b Js not greater than,
Eyaluate Values and, vasiepless
“Me bod) Function allows us to evaluate any vatue and give
ug hue ov False in return,
eq @ Evaluate a eats and a number:
))
priat C bool C" Hell 4b Toue
pring ( bed (159) Teue
Evalue too vosdables:
x= “Hello”
ae ae True
sink ( bool (>) True.
point ( dedl(4))
© scanned with OKEN Scanner| OE WANE Cre LUC,
\ .
value wig evatucted, to Te, if it hay some
Almost anc
Sort of content,
* ang stsing is Taus,, except empty stsings
* Any numbex. dis Toye , except o
+ Any tisk, duple, set and dtctionas¢ ane True» except
empty one.
eg. Te following will seturn Tues
bool ("abc")
bool C123 :
boat C Te abl scherrg's arene’)
oe True
True
Tue,
Some, Values Qs false:
e-g. The following. sill ~setusn False:
bool (False) aie
bool (None) False
False
‘bool (0) aie
bool C"") False
best (0) false
tol (2) es
bool C43)
one more value, or Objeck inthis care, evaduertes -to
False and that is if we shave an object that ts
made from a class with — len function that -relurng
o or False.
© scanned with OKEN Scannerclass. myé lassO;
def len Calf):
yelumno ae oculpats False
mycby = mychss()
prnt (bos Comyohf))
funetions can Rela a Roslean,
+ WE CAN Create, functions Aha returns a Roolean value:
eq.
| det my function):
reluyn True, eee
print (my function)
ewe Can execute Code based. on the Rodean answers of U
Function:
“4 . Paint" Yes|" if the Punetion yetusns True, otherwise
print "Nol" s
det my function:
return) True de Yesh
id myfunctionO)s
pink yest")
elses
print ("No")
+ athen algo “Ras many builtin functions thak vetun a
sean yotue , ke isinskaneO which can be used. to
pees
detesemine 4 an object ig of O Coutain data types
eq. check ig an object isan integex ov nots
t= 200
print ( Isinstance. (x, {nt))
+e Toue-
© scanned with OKEN ScannerPythen ppowaters
' Operetors ae ((
NE t efor vali i
ee Ised ty peeform opexalions on vastiabl eg
0 -
+ Pathon ctivides he operators fn the {
© Arithmetic. Operators
: Assignment ppereators
© Compariizon Qpoxators
© Logical Hpoealors
Identity. 6p vrators
+ Membexship Opexcctors
© Bitwise optwators.
Python, fyithanedie epecaless,
used. with numesde values to
« Astthmetic Opeeators ase n
perform Common mathemati cal opexcadions:
lowing growpss
operator | Name arp |
+ Addition x+y 2
print O44)
- Subtraction | 43 #2
print(x-Y)
*” Mubti plication x xe8 415
: print@txy) 7
/ Division oly ay es
print (x14)
% Modulus Nf EES HEI
: int AH)
4x Exponentiakion pane {=e
25
paint x 4) Baas
oe frame ay 24282822
Il Floor Division alt 42 tet
pa pane (aly
a¢ Phorctiviclen fr pounds the resutt Nowy to We nearest
© scanned with OKEN Scanner(i)
yihoy Assignment Onewile
. 1 |
csignment bptealots Are, used -to assign values to variables,
1-5 potato 4S
= X4+=3 eS 15
paaition — Lyd #e
a csignmsnt) print (x)
X-=3 = x3 es 4 2
Lee3 Y= X¥3 2534 4E IS
iM OO
xXpad t=% x= 16666664
! 13 tos
pal 169)
Lh=d LEC 3 1+5
; xyes te
printor)
x= = ce
ll=3 x= X13) a I
print ct)
= =e =S
28 aS (EL, ens
paintco
=3 =th3 Xs
a * x23 FI
) panten)
xl=3 x= X13 x=5
xj=3 HF
) pinto)
Az ped x= XS X=
Chote a2
KOR ossignmyent) paint)
>= T= = 7 =
eit ist a | X= X>>d tO aor
este print oo)
Ka = LarX Greajex, than wry 4 3
pine (x4)
He True
& Less thot x “t a5 2
tint (% »
. de false
ase Greate than oF trey 3
eget, to i (2-4)
ar Toe
= Lew than oF 2 =
7 < i oF eqpol, | ez t es
print(xc=¥)
i A False
Pathan Leica @pecaloss,
- Lagical operators axe wed, fo combine conditional:
opevaior | Desced’ption [ Eample
~ “and Retusns True tf beth [x5 and Kxto | T=5
Statements axe True PRint(X>3 and x< 10)
HF True
Returns True H One | xs ory za [xes
ig of the statements A pink (2053 09 x4)
is true tt True.
© scanned with OKEN Scannerth oe . L
| Taentity- Spreaders QO tuked fo Compare the obgects, Not
if they Qe equ, but if they ie actual
ji Mr the Same.
absetks Worth the Same memory. locations
Cpeeater | Deseseibtion Example :
is Returns True 1 both ‘ X= PP aphle’, "banana"
Yuuiables ace he some | ae aie ee
Object. ee
print (x is z)
print (cis +9)
paint Cx ==Y)
- $e Tue
False
Tue Et
| Relumns True if both . r=["abpl', banana’) !
isnot | Vasdiabsles ase, ot the & isnot y= Capt, “banana"}
Same Obgeck. Lar
sink (cis not z)
pring (isnot yt)
print (X1F yf)
ae False,
Prue
False
| /
© scanned with OKEN ScannerMembeuchit
prevented
Operator Dercdbtion allen
| Returns True FO sequence
Ademaduts ane.
fin an objects
with the. split yale
is pent ty the obfeck
used to toat ifa
Example
sequence is
x =["apple’ "banana
print" banda! in
x)
- [tt True
Returns True. 14 a sequincel x-[" apple’, "banara]
usth the sbecistied yalue prink(* Fine ple! nok
is Not present fn the in *)
Obgeck
ok True
Futon aS
Binary Gpeandors axe used 4o compar ( Binary )mumberss
“ pptxator [Name Dacuiption Gxarrple ele
z AND Sets each BE ToT TF AH [xe y [print (643) Ts
bits axel HR y
| OR _|sets each bi to 1 if one of alt print (63)
Huo bits is | tha Hn
A | KOR ‘Sets each Bik fo1 iF only one oc ~ fpsint (6%3)
of two bits is | aS »
~ NoT Tnveds all the bits ne paint (3)
eo
il Fr Oy paling, zen ny
<7 leviy ten ae ee
leftmost bits fall ob
7 Shab WghE by. pwhing whe] int
» sy nae [ot ae inte ei a peal ery
Tight SNE Tine gett and det the HR
Tighemest bits fall oy.
© scanned with OKEN Scanner&
gator prece Vence. devemiken dhe. ardor in which mpewati
cretormed
precedence Otclex. an deyemtbed in the fable. below, -ttuel'ag
ah the highest precedence at the fop2—
stor im. ide -
Cyambl)
aT +
| farentheses nk((6+3)- (643) 9-9
sto 7
Expon entiation paint (Ioo- 3°*3) [oo +
| ae 48 it
Tx 7% | Unasy plus, uw minus and | print (loo-+ ~3) \oo-+ 4
| bikwige Not mt aC =
|
Maltiplication, clivision Ploorpivsoh pant (IOOFS*3) |
aad ‘motusluy 5 7
Addition and sublackion — | pant (lo0- 5%3) ied
ares i
Bitwise lef and right” | prin (B42) a
shifts +2
Bikwise AND paint (622-41) a=
ot 2 ca
is
BitwiseyoR print (642 +1) 6430 ts
+S m7
Bitwise OR paint (6] 2 +1) 5S ts
cane —_
FF > >= €<-] Compasesons, identity. and | print (5=- 4+) Bees
cnet in oin Mmembexshi p Speakers te True
Not Logical NOT print (nok 5 ==5)
# False
and AND Paint Clor2and sy [(or3=1
31
or ORo [anrc Fors “Floor 8) ela
© scanned wit
h OKEN Scanneryn 2, tHe GAPE
© Tf 4wo ppexaieer rave the same precedence, ¥
1 on
ts. evaluated fom left +o rights
Exainple +
Addition + and subbraction — has the same prececlence and
jhecefore woe evaluate the exbyession {eam left to rights
pant (SH 448) arg
2 9-4-2
. 243-5
© scanned with OKEN Scanner