0% found this document useful (0 votes)
5 views7 pages

Statements

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)
5 views7 pages

Statements

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/ 7

syntax

if some condition
execute some code

Ee dit some other condition we can stack


nde do elif's
something
else
dosomethingelse

EI hungry True
if hungry
Print FEED ME
Op FEED ME

FOLLOOPS
for nom in list
Eze list 12,345,6 7,8 9,10 my
my it numy 2 20
for nom in list
my print nom
print Eh
ifpantaum
Ocp h they
u
n to
getsprinted 6
h Ex Helloworld
h mystring
for letter in mystring
h
print letter
h
h Op H TUPLE
h i r UNPACKING
h
n I
I
list of tuples
É my
list sa za Ed fed
ten mylist Ec for a b in mylist
Print b
Op
for item in list Op 2
Ez my y
print item 8
Op 1,2
39 É my list 52,3 156,7
8,9 10
go
8
for a b c in mylist
print b
Op 2

É'd ki 1 K2 2,11931 3

for item in d
default when we
print item By
iterate thru diets
Op ki
we iterate thru
K2 only
the
Kz keys

If at all items
we want to iterate through
Ez for item in d items
item
print
Op C Ki D
K2 2
EK3 3
Ex for value in d values tuple

01ps I
print value
of unpacking

will continue to execute


While While loops
loops condition remains True
code while
Fdot while
some
boolean condition
some
Syntax
dosomething

EE n0
while x 25
print f The currentvalueof x is 23
X Xt I

Op The currentvalueof x is o
The currentvalueof x is 1
value
The current of x is 2
The currentvalueof x is 3
The currentvalueof x is a
Break breaksout of the currentclosing
keywords in loops continue en a
Goes to thetop of the loop
closest
ty
Ee mystringIsang pass Does nothingat all
for letter in aged as placeholderalso to avoid syntax
string
my errors
if letter as'd
Ex for break
continue 2 0
printcette while x 25
if X 2
Op S
break
printer
YM l
Xt
Op
9
Useful operators in Python
for 3,103
range
nom in range
print
3
Guy the to
all wayup

8
G 10 but not
including
it
g 3rd argument
as
We can also include stepsize
0,1523 2
for nom in
range sgp
Ex print nom d
jump 8
enumerate often when dealing with iterations also we
need to keep count of iterations Enumerate
method adds a counter to an iterable and
returns it in a form of enumerating object
word abd
Is word abode
enumerate word
Ez
for index letter in enumerate
for item in word
print item print index
letter
Ip Co la print
s b print un
2 C't Op E
3 dD i

U e b

2
is an
The zip function returns a which
Ip of zip object
eachpassed iterator
iterator tuples where the first item in
item in each 11
ispaired
together and then the second
John Charles Mike
EI a

be Jenny Christy Monica Vicky


zip ab to
x
we need to write this
versionof
print tuple display a readable
x

result
Op John Jenny Charles Christy Mike Monica'd

items these items are


If one tuple contains more

ignored
Ecs.my sti 133,456 Ed D Zmykey 3 us
b d
my lista a Bus in dkeysc
list zipcmylistl.mylist 2 Opp False

3 d list 100200,350
L ay La d
Eg my
mylist
min
maxmylist
for nom in ranges Op
printGum 3
Randomis abuiltin python
9p until 5 notincluding library
I
ca in
j
keyword
a world
EI from random importshuffle
my
list

shuffle
523,456,789
list 103
Eze my
my list
Otp True
49,3110 6,5 3,7 8
from randomimpostrandint
Es
randint ooo Ajustgiving an interval
79
Alwaysaccepts as a
string
Etyy
In
flattened out forloop
List Comprehension
word
Ed mylist x for xin
list
my
d
Op w o r

EE my list momma for no min


range oil
mylistl
0 p O b 4,9 16 25,36 9964,811003
for x inrange gli if x 2 0
Even
Ez mylista
lists
x
y
my
Op 0,2 4 6,8 103

Eg my list E
for x in 2,4 6
300
for in 100,20
y list
append g
my list
my 600,1200 18003
200 600 600,460,800,1200

EI when we write the above code as listcomprehens

Imylistlist Xy for xin 2,46 for 10 209300


yin
my

You might also like