Class Test-11.11
Class Test-11.11
f. Insert 25 at index 3
2. If a is [1, 2, 3]
b. is a * 3 equivalent to a + a + a?
3. What does each of the following expressions evaluate to? Suppose that L is the list
["These", ["are", "a", "few", "words"], "that", "we", "will", "use"].
a. L[1][0::2]
b. "a" in L[1][0]
c. L[:1] + L[1]
d. L[2::2]
e. L[2][2] in L[1]
4. What are list slices? What for can you use them?
5. Compare lists with strings. How are they similar and how are they different?
7. What is the difference between following two expressions, if lst is given as [1, 3, 5]
1. L1 == L2
2. L1.upper( )
3. L1[3].upper( )
4. L2.upper( )
5. L2[1].upper( )
6. L2[1][1].upper( )
10. Given a list L1 = [3, 4.5, 12, 25.7, [2, 1, 0, 5], 88], which function can change the list to:
my_list[2:3] = []
print(my_list)
my_list[2:5] = []
print(my_list)
print(List1.index(18))
print(List1.count(18))
List1.append(List1.count(13))
print(List1)
13. Predict the output of following two parts. Are the outputs same? Are the outputs different? Why?
(a)
L3 = L2
L2[1] = 5
print(L3)
(b)
L1, L2 = [2, 4] , [2, 4]
L3 = list(L2)
L2[1] = 5
print(L3)
2. L2 = L1 + 2
3. L3 = L1 * 2
4. Idx = L1.index(45)
y = ''
while x:
y = y + x[-1]
x = x[:len(x) - 1]
print(y)
print(x)
print(type(x), type(y))