Python Programming (2180711) MCQs

MCQs of Structured Types, Mutability and Higher-Order Functions

Showing 11 to 20 out of 48 Questions
11.
What will be the output of the following Python code?
print('abcdefcdghcd'.split('cd', -1))
(a) [‘ab’, ‘ef’, ‘gh’]
(b) [‘ab’, ‘ef’, ‘gh’, ”]
(c) (‘ab’, ‘ef’, ‘gh’)
(d) (‘ab’, ‘ef’, ‘gh’, ”)
Answer:

Option (b)

12.
Which of the following commands will create a list?
(a) list1 = list()
(b) list1 = []
(c) list1 = list([1, 2, 3])
(d) all of the mentioned
Answer:

Option (d)

13.
What is the output when we execute list(“hello”)?
(a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
(b) [‘hello’]
(c) [‘llo’]
(d) [‘olleh’]
Answer:

Option (a)

14.
To shuffle the list(say list1) what function do we use?
(a) list1.shuffle()
(b) shuffle(list1)
(c) random.shuffle(list1)
(d) random.shuffleList(list1)
Answer:

Option (c)

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

Option (d)

16.
What will be the output of the following Python code?
a=[10,23,56,[78]]
b=list(a)
a[3][0]=95
a[1]=34
print(b)
(a) [10,34,56,[95]]
(b) [10,23,56,[78]]
(c) [10,23,56,[95]]
(d) [10,34,56,[78]]
Answer:

Option (c)

17.
What will be the output of the following Python code?
print(list(zip((1,2,3),('a'),('xxx','yyy'))))
print(list(zip((2,4),('b','c'),('yy','xx'))))
(a)
[(1,2,3),(‘a’),(‘xxx’,’yyy’)]
[(2,4),(‘b’,’c’),(‘yy’,’xx’)]
(b)
[(1, 'a', 'xxx'),(2,’ ‘,’yyy’),(3,’ ‘,’ ‘)]
[(2, 'b', 'yy'), (4, 'c', 'xx')]
(c) Syntax error
(d)
[(1, 'a', 'xxx')]
[(2, 'b', 'yy'), (4, 'c', 'xx')]
Answer:

Option (d)

18.
To which of the following the “in” operator can be used to check if an item is in it?
(a) Lists
(b) Dictionary
(c) Set
(d) All of the mentioned
Answer:

Option (d)

19.
To remove string “hello” from list1, we use which command?
(a) list1.remove(“hello”)
(b) list1.remove(hello)
(c) list1.removeAll(“hello”)
(d) list1.removeOne(“hello”)
Answer:

Option (a)

20.
Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?
(a) 0
(b) 1
(c) 4
(d) 2
Answer:

Option (d)

Showing 11 to 20 out of 48 Questions