0% found this document useful (0 votes)
30 views3 pages

Class Test-11.11

Uploaded by

gspsresource
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

Class Test-11.11

Uploaded by

gspsresource
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. Start with the list [8, 9, 10].

Do the following using list functions:

a. Set the second entry (index 1) to 17

b. Add 4, 5 and 6 to the end of the list

c. Remove the first entry from the list

d. Sort the list

e. Double the list

f. Insert 25 at index 3

2. If a is [1, 2, 3]

a. what is the difference (if any) between a * 3 and [a, a, a]?

b. is a * 3 equivalent to a + a + a?

c. what is the meaning of a[1:1] = 9?

d. what's the difference between a[1:2] = 4 and a[1:1] = 4?

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?

6. What is the difference between appending a list and extending a list?

Type B: Application Based Questions

7. What is the difference between following two expressions, if lst is given as [1, 3, 5]

(i) lst * 3 and lst *= 3


(ii) lst + 3 and lst += [3]

8. Given two lists:

L1 = ["this", 'is', 'a', 'List'], L2 = ["this", ["is", "another"], "List"]

Which of the following expressions will cause an error and why?

1. L1 == L2

2. L1.upper( )

3. L1[3].upper( )
4. L2.upper( )

5. L2[1].upper( )

6. L2[1][1].upper( )

9. Given a list L1 = [3, 4.5, 12, 25.7, [2, 1, 0, 5], 88]

1. Which list slice will return [12, 25.7, [2, 1, 0, 5]]?

2. Which expression will return [2, 1, 0, 5]?

3. Which list slice will return [[2, 1, 0, 5]]?

4. Which list slice will return [4.5, 25.7, 88]?

10. Given a list L1 = [3, 4.5, 12, 25.7, [2, 1, 0, 5], 88], which function can change the list to:

1. [3, 4.5, 12, 25.7, 88]

2. [3, 4.5, 12, 25.7]

3. [ [2, 1, 0, 5], 88]

11. Predict the output:

my_list= [ 'p', 'r', 'o', 'b', 'l' , 'e', 'm']

my_list[2:3] = []

print(my_list)

my_list[2:5] = []

print(my_list)

12. Predict the output:

List1 = [13, 18, 11, 16, 13, 18, 13]

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)

L1, L2 = [2, 4] , [2, 4]

L3 = L2

L2[1] = 5

print(L3)

(b)
L1, L2 = [2, 4] , [2, 4]

L3 = list(L2)

L2[1] = 5

print(L3)

14. Find the errors:

1. L1 = [1, 11, 21, 31]

2. L2 = L1 + 2

3. L3 = L1 * 2

4. Idx = L1.index(45)

15. What will be the output of following code?

x = ['3', '2', '5']

y = ''

while x:

y = y + x[-1]

x = x[:len(x) - 1]

print(y)

print(x)

print(type(x), type(y))

You might also like