List Notes
List Notes
Answer:
Answer:
Answer:
Output:
Final List: [123, ‘xyz’, ’zara1, 2009,’abc1’]
8. Write the output of the given python code :
Answer:
Output:
A List: abc B List: zara
9. How are lists different from strings when both are sequences ?
Answer:
The lists and strings are different in following ways :
(a) The lists are mutable sequences while strings are immutable.
(b) Strings store single type of elements, all characters while lists can store
elements belonging to different types.
(c) In consecutive locations, strings store the individual characters while list
stores the references of its elements.
10. Write a program to calculate and display the sum of all the odd numbers in the
list.
Answer:
pos = 0
sum = 0
while pos < len (L):
if L[pos] %2 = = 1 :
sum = sum + L [pos]
pos = pos + 1
print sum
14. Write a program to input any two tuples and interchange the tupel values.
Answer:
t1 = tuple( )
n = input(“Total number of values m first tuple”) for i in range (n):
a = input(“Enter elements”)
t2 = t2 + (a, )
print “First tuple”
print t1
print “Second tuple”
print t2
t1, t2 = t2, t1
print “After swapping”
print “First tuple”
print t1
print “Second tuple”
print t2
15.