Python MCQs on Modules: SET 9

81. What will be the output of the following Python function, assuming that the random library has already been included?


a) Randomized list containing the same numbers in any order

b) The same list, that is [1,2,24]

c) A list containing any random numbers between 1 and 24

d) Error

Check Answer

Answer: d
The function shown above will result in an error because this is the incorrect syntax for the usage of the function shuffle(). The list should be previously declared and then passed to this function to get an output.
An example of the correct syntax:
>>> l=[‘a’,’b’,’c’,’d’] >>> random.shuffle(l)
>>> print(l)

82. What the does random.seed(3) return?

a) True

b) None

c) 3

d) 1

Check Answer

Answer: b
The function random.seed() always returns a None.

83. Which of the following cannot be returned by random.randrange(4)?

a) 0

b) 3

c) 2.3

d) none of the mentioned

Check Answer

Answer: c
Only integers can be returned.

84. Which of the following is equivalent to random.randrange(3)?

a) range(3)

b) random.choice(range(0, 3))

c) random.shuffle(range(3))


Check Answer

Answer: b

It returns one number from the given range.

85. The function random.randint(4) can return only one of the following values. Which?

a) 4

b) 3.4

c) error

d) 5

Check Answer

Answer: c
Error, the function takes two arguments.

86. Which of the following is equivalent to random.randint(3, 6)?

a) random.choice([3, 6])

b) random.randrange(3, 6)

c) 3 + random.randrange(3)

d) 3 + random.randrange(4)

Check Answer

Answer: d
random.randint(3, 6) can return any one of 3, 4, 5 and 6.

87. Which of the following will not be returned by random.choice(“1 ,”)?

a) 1

b) (space)

c) ,

d) none of the mentioned

Check Answer


Answer: d
Any of the characters present in the string may be returned.

88. Which of the following will never be displayed on executing print(random.choice({0: 1, 2: 3}))?

a) 0

b) 1

c) KeyError: 1

d) none of the mentioned

Check Answer

Answer: a
It will not print 0 but dict[0] i.e. 1 may be printed.

89. What does random.shuffle(x) do when x = [1, 2, 3]?

a) error

b) do nothing, it is a placeholder for a function that is yet to be implemented

c) shuffle the elements of the list in-place

d) none of the mentioned

Check Answer


Answer: c
The elements of the list passed to it are shuffled in-place.

90. Which type of elements are accepted by random.shuffle()?

a) strings

b) lists

c) tuples

d) integers

Check Answer

Answer: b
Strings and tuples are immutable and an integer has no len().

Page  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15      16 

Python Interview Questions (MCQs)

We have divided these Python Questions and Answers into various parts based on the topics. Open the Topic of your choice and Practice these MCQs.

Python MCQs on Variables and Operators Python MCQs on Precedence and Associativity
Python MCQs on Data Type Python MCQs on Boolean
Python MCQs on Bitwise Operators Python MCQs on Formatting and Advance Formatting
Python MCQs on Decorators Python MCQs on While and For Loops
Python MCQs on List Python MCQs on List Comprehension
Python MCQs on String Python MCQs on Tuple
Python MCQs on SET Python MCQs on Dictionary
Python MCQs on Functions Python MCQs on Argument Parsing
Python MCQs on Global and Local Variables Python MCQs on Recursion
Python MCQs on Mapping Functions Python MCQs on Modules
Python MCQs on Regular Expressions Python MCQs on Files
Python MCQs on Overloading Python MCQs on Classes and Objects
Python MCQs on Inheritance Python MCQs on Polymorphism and Encapsulation
Python MCQs on Exception Handling


Leave a Comment