Difference between revisions of "Control Flow, if statements etc.."
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
=If Statemts= | =Python If Statemts= | ||
name = "b" | name = "b" | ||
if name == 'robert': | if name == 'robert': | ||
Line 7: | Line 7: | ||
else: | else: | ||
print('wrong name') | 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) |
Revision as of 20:14, 6 January 2019
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)