In [13]:
tup = [(1,2), (3, 4), (5,6)]
In [14]:
for t in tup:
print(t)
In [18]:
[(t1, t2) for (t1, t2) in tup]
Out[18]:
In [4]:
# tuple unpacking
In [7]:
for t1, t2 in tup:
print(t1)
print(t2)
In [15]:
dic = { "k1": None, "k2": "value 2", "k3": "value 3"}
In [16]:
for key in dic:
print(key)
In [19]:
print(dic["k2"])
In [20]:
# python 3
for k,v in dic.items():
print(k, v)
In [21]:
# python 2
for k,v in dic.iteritems():
print(k, v)
In [27]:
#basics
x = 0
while x < 10:
print "x is currently:", x
x += 1
In [10]:
# break continue pass
y = 0
while y < 12:
print 'x is', y
if y == 4:
# pass # does nothing
print 'continue'
y += 4
continue
if y == 10:
print 'break'
break # breaking breaks out of while and doesn't run else
y += 1
else:
print 'we\'ve finished'
In [ ]: