(2) Develop programs to learn different types of Structures (List, Dictionary, Tuples) in python
Program Code:
# Iterating over a list
print("List Iteration")
l = ["Python", 'P', 20]
for i in l:
print(i)
# Iterating over a tuple (immutable)
print("\n Tuple Iteration")
t = ("Python", 'P', 20)
for i in t:
print(i)
# Iterating over dictionary
print("\n Dictionary Iteration")
d = dict()
d['Python'] = 123
d['GTU'] = 345
d['Hello'] = 45
d['Hi'] = 99
for i in d :
print("%s %d" %(i, d[i]))
Output:
No comments:
Post a Comment