Python Online Quiz


Advertisements


Following quiz provides Multiple Choice Questions (MCQs) related to Python. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - Which of the following data types is not supported in python?

A - Numbers

B - String

C - List

D - Slice

Answer : D

Explanation

Slice is not a supported data type.

Q 2 - What is the output of print list if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?

A - [ 'abcd', 786 , 2.23, 'john', 70.2 ]

B - list

C - Error

D - None of the above.

Answer : A

Explanation

[ 'abcd', 786 , 2.23, 'john', 70.2 ] is the correct answer.

Q 3 - Which of the following function of dictionary gets all the keys from the dictionary?

A - getkeys()

B - key()

C - keys()

D - None of the above.

Answer : C

Explanation

Using dictionary.keys() function, we can get all the keys from the dictionary object.

Q 4 - Which of the following function of dictionary gets all the values from the dictionary?

A - getvalues()

B - value()

C - values()

D - None of the above.

Answer : C

Explanation

Using dictionary.values() function, we can get all the values from the dictionary object.

Q 5 - Which of the following operator in python evaluates to true if the variables on either side of the operator point to the same object and false otherwise?

A - **

B - //

C - is

D - not in

Answer : C

Explanation

is − Evaluates to true if the variables on either side of the operator point to the same object and false otherwise. x is y, here is results in 1 if id(x) equals id(y).

Q 6 - Which of the following function sets the integer starting value used in generating random numbers?

A - choice(seq)

B - randrange ([start,] stop [,step])

C - random()

D - seed([x])

Answer : D

Explanation

seed([x]) − Sets the integer starting value used in generating random numbers. Call this function before calling any other random module function. Returns None.

Q 7 - Which of the following function checks in a string that all characters are in uppercase?

A - isupper()

B - join(seq)

C - len(string)

D - ljust(width[, fillchar])

Answer : A

Explanation

isupper() − Returns true if string has at least 1 character and all characters are in uppercase.

Q 8 - Which of the following function returns titlecased version of string?

A - replace(old, new [, max])

B - strip([chars])

C - swapcase()

D - title()

Answer : D

Explanation

title() − Returns "titlecased" version of string, that is, all words begin with uppercase and the rest are lowercase.

Q 9 - What is the output of len([1, 2, 3])?

A - 1

B - 2

C - 3

D - 4

Answer : C

Explanation

3

Q 10 - What is the following function reverses objects of list in place?

A - list.reverse()

B - list.sort([func])

C - list.pop(obj=list[-1])

D - list.remove(obj)

Answer : A

Explanation

list.reverse() − Reverses objects of list in place.


python_questions_answers.htm

Advertisements