0% found this document useful (0 votes)
3 views

IX_Assignment-5_Ch-4_List_in_Python_-SOLVED[1]

Uploaded by

sparsh Bansal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

IX_Assignment-5_Ch-4_List_in_Python_-SOLVED[1]

Uploaded by

sparsh Bansal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ASSIGNMENT-5

Unit-5 / Chapter-4 List in Python


Topic: Creating list, built-in functions (append, insert, extend, remove, pop), slicing of a list

1. Which of the following commands will create a list?


a) list1 = list() c) list1 = list([1, 2, 3])
b) list1 = [] d) all of the mentioned

2. What is the output when we execute list(“hello”)?


a) *‘h’, ‘e’, ‘l’, ‘l’, ‘o’+ c) *‘llo’+
b) *‘hello’+ d) *‘olleh’+

3. Suppose listExample is *‘h’,’e’,’l’,’l’,’o’+, what is len(listExample)?


a) 5 c) None
b) 4 d) Error

4. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], which of the following is correct syntax for slicing
operation?
a) print(list1[2:]) c) print(list1[:-2])
b) print(list1[:2]) d) all of the mentioned

5. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?


a) Error c) 25
b) None d) 2

6. Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?


a) [2, 33, 222, 14] c) 25
b) Error d) [25, 14, 222, 33, 2]

7. What will be the output of the following Python code?

a) A c) Error
b) Daman d) n

8. Suppose list1 is [1, 3, 2], what is list1 * 2?


a) [2, 6, 4] c) [1, 3, 2, 1, 3, 2]
b) [1, 3, 2, 1, 3] d) [1, 3, 2, 3, 2, 1]

9. Which of the following methods is used to add an element to the end of a list in Python?
a) append() c) insert()
b) add() d) extend()
10. Which of the following methods is used to remove the first occurrence of a specified
element from a list in Python?
a) remove() c) delete()
b) pop() d) discard()
11. What will be the output of the following Python code snippet?
my_list = [1, 2, 3, 4, 5]
my_list.pop(2)
print(my_list)
a) [1, 2, 4, 5] c) [1, 2, 4]
b) [1, 2, 3, 5] d) [1, 2, 3, 4]
12. Which of the following methods is used to reverse the elements of a list in Python?
a) reverse() c) swap()
b) sort() d) invert()
13. What is the output of the following Python code snippet?
my_list = [1, 2, 3, 4, 5]
my_list.extend([6, 7, 8])
print(my_list)
a) [1, 2, 3, 4, 5, 6, 7, 8] c) [1, 2, 3, 4, 5, (6, 7, 8)]
b) [1, 2, 3, 4, 5, [6, 7, 8]] d) [1, 2, 3, 4, 5, {6, 7, 8}]
14. What will be the output of the following Python code snippet?
my_list = [3, 2, 1, 4, 5]
my_list.sort()
print(my_list)
a) [1, 2, 3, 4, 5] c) [3, 2, 1, 4, 5]
b) [5, 4, 3, 2, 1] d) [1, 3, 2, 4, 5]
15. What is the output of the following Python code snippet?
my_list = [1, 2, 3, 4, 5]
my_list.insert(2, 10)
print(my_list)
a) [1, 2, 10, 3, 4, 5] c) [1, 2, 3, 4, 10, 5]
b) [1, 2, 3, 10, 4, 5] d) [1, 2, 3, 4, 5, 10]

16. What will be the output of the following Python code snippet?
my_list = [1, 2, 3, 4, 5]
my_list.remove(3)
print(my_list)
a) [1, 2, 4, 5] c) [1, 2, 4]
b) [1, 2, 3, 4] d) [1, 2, 5]

17. What will be the output of the following Python code snippet?
my_list = [1, 2, 3]
new_list = my_list.copy()
my_list.append(4)
print(new_list)
a) [1, 2, 3] c) [1, 2, 3, 4]
b) [1, 2, 3, 4] d) [1, 2, 3, 4]
18. To add a new element to a list we use which command?
a) list1.add(5) c) list1.addLast(5)
b) list1.append(5) d) list1.addEnd(5)

19. To insert 5 to the third position in list1, we use which command?


a) list1.insert(3, 5) c) list1.add(3, 5)
b) list1.insert(2, 5) d) list1.append(3, 5)

20. To remove string “hello” from list1, we use which command?


a) list1.remove(“hello”) c) list1.removeAll(“hello”)
b) list1.remove(hello) d) list1.removeOne(“hello”)

21. Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?


a) 0 c) 4
b) 1 d) 2

22. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?


a) 0 c) 1
b) 4 d) 2

23. What will be the output of the following Python code?

a) 2 c) 5
b) 4 d) 8

24. What will be the output of the following Python code?

a) *‘carrot’, ‘celery’, ‘broccoli’, ‘potato’, ‘asparagus’+


b) *‘carrot’, ‘celery’, ‘potato’, ‘asparagus’+
c) *‘carrot’, ‘broccoli’, ‘celery’, ‘potato’, ‘asparagus’+
d) *‘celery’, ‘carrot’, ‘broccoli’, ‘potato’, ‘asparagus’+

You might also like