Control Flow, if statements etc..

From rbachwiki
Revision as of 20:14, 6 January 2019 by Bacchas (talk | contribs)
Jump to navigation Jump to search

Python If Statemts

name = "b"
if name == 'robert':
   print(name)
elif name == 'john':
   print(name)
else:
   print('wrong name')

Python Loops

list2 = [(2,4),(6,8),(10,12)]
for tup in list2:
   print(tup)

output

(2, 4)
(6, 8)
(10, 12)

Now with unpacking

for (t1,t2) in list2:
   print(t1)

Output

2
6
10

Another Example

d = {'k1':1,'k2':2,'k3':3}
for item in d:
   print(item)