HI AGAIN
PYTHON UNLEASH'D 04
Back with basics, grinding on loops in python. Life becomes really hard when you have to manage so many things
Anyways, focus on agenda!
We know about for loop, lets look at its basic syntax first.
for loop with list
for name in list1:
print(name)
for loop within range
list2 = [1,2,3,4,5,6]
for i in range(0,6,2):
print(list2[i])
for loop with dictionaries
d = dict()
d['a'] = 123
d['b'] = "hehe"
for i in d:
print(i,d[i])
zip() used to traverse two list together
fruits = ["apple", "banana", "cherry"]
colors = ["red", "yellow", "green"]
for fruit, color in zip(fruits, colors):
print(fruit, "is", color)
Tuple
tup = (1,2,3,4,"holy")
for a in tup:
print(a)
t = ((1, 2), (3, 4), (5, 6))
for a, b in t:
print(a, b)
Good examples
See you in next blog guys!
Happy reading...
Top comments (0)