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 - What is the output for −

'python ' [-3]?

A - 'o'

B - 't'

C - 'h'

D - Negative index error.

Answer : C

Explanation

Negative indexes begin toward the end of a string and go in reverse.

Q 2 - What is output of following code −

x = 2
y = 10
x * = y * x + 1

A - 42

B - 41

C - 40

D - 39

Answer : A

Explanation

x * = y * x + 1 means x = x * (y * x + 1)

Q 3 - When the given code is executed how many times ' 'you are learning python ' ' will be printed.

a = 0
while a<10:
… print(''you are learning python'')
… pass

A - 9

B - 10

C - 11

D - Infinite number of times.

Answer : D

Explanation

The loop will execute infinite number of times because there is no statement specified for end of loop and pass indicates nothing is to be done.

Q 4 - what is output of following code −

class Count:
   def __init__(self, count=0):
      self.__count=count
a=Count(2)
b=Count(2)
print(id(a)==id(b), end = '' '')

c= ''hello''
d= ''hello''
print(id(c)==id(d))

A - True False

B - False True

C - False False

D - True True

Answer : B

Explanation

The objects with same contents share the same object in the python library but this is not true for custom-defined immutable classes.

Q 5 - What is output of following −

print(''abbzxyzxzxabb''.count(‘abb’,-10,-1))

A - 2

B - 0

C - 1

D - Error

Answer : B

Explanation

It Counts the number of times the substring ‘abb’ is present starting from position 2 and ending at position 11 in the given string.

Q 6 - What is the output of the following code?

eval(''1 + 3 * 2'')

A - ‘1+6’

B - ‘4*2’

C - ‘1+3*2’

D - 7

Answer : D

Explanation

Eval is a method used to evaluate the values entered in the braces.

Answer : C

Explanation

+ Operator cannot be operated on the sets.

Q 8 - Which function can be used on the file to display a dialog for saving a file?

A - Filename = savefilename()

B - Filename = asksavefilename()

C - Fielname = asksaveasfilename()

D - No such option in python.

Answer : C

Explanation

This is the default method to display a dialog for saving a file in Tkinter module of Python.

Answer : C

python_questions_answers.htm
Advertisements