Python Online Quiz



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 - Name the python module which supports regular expressions.

A - regex

B - re

C - pyre

D - pyregex

Answer : B

Explanation

re is the module which supports regular expressions and is part of standard library.

We can import re module as − import re.

Q 3 - Name the error that doesn't cause program to stop/end, but the output is not the desired result or is incorrect.

A - Syntax error

B - Runtime error

C - Logical error

D - All of the above

Answer : C

Explanation

logical error doesn't cause the program to stop/end, but the output is not the desired result or is incorrect.

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.

Answer : B

Explanation

x is the object created by the constructor of the class Circle().

Q 7 - Suppose you are given a set(s1={1,2,3}) then what is the output for the code −

2 * s1?

A - (1,1,2,2,3,3)

B - [1,1,2,2,3,3]

C - Illegal

D - (1,2,3,1,2,3)

Answer : C

Explanation

* cannot be operated on the sets.

Answer : D

Explanation

You need to define the format in which you want to open the file. Proper path has to be declared by the user for the interpreter to reach the destination of the file.

Q 9 - Select the correct option to draw a rectangle centred at 50,50 with width and height as 50, 70 respectively.

A - Canvas.create_rect(50,50,50,70)

B - Canvas.create_rect(50,70,50,50)

C - Canvas.create_rectangle(50,50,50,70)

D - Tkinter.create_rect(50,50,50,70)

Answer : C

python_questions_answers.htm
Advertisements