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 −

S = [['him', 'sell'], [90, 28, 43]]

S[0][1][1]

A - 'e'

B - 'i'

C - '90'

D - 'h'

Answer : A

Explanation

List can contain other list values.

So, in this question S[0] gives ['him', 'sell'], S[0][1] gives ‘sell' and S[0][1][1] gives ‘e'.

Remember, the index in python starts with ‘0'.

Q 2 - What is output for −

b = [11,13,15,17,19,21]

ptint(b[::2])

A - [19,21]

B - [11,15]

C - [11,15,19]

D - [13,17,21]

Answer : C

Explanation

b[::2] :- it iterates over the list with ‘2' increments

Answer : B

Explanation

list are mutable whereas tuples are immutable i.e. in list changes can be made but in tuples it is not possible, they can only be operated its value cannot be changed.

Q 4 - What is output of following code −

def func(n):
   if(n==1):
      return 1;
   else:
      return(n+func(n-1))
print(func(4))

A - 12

B - 10

C - 9

D - 11

Answer : B

Q 5 - What is output of following code −

l = [1,2,6,5,7,8]
l.insert(9)

A - l=[9,1,2,6,5,7,8]

B - l=[1,2,6,5,9.7,8] (insert randomly at any position)

C - l=[1,2,6,5,7,8,9]

D - Type Error

Answer : D

Explanation

listname.insert(x,y) method is used to insert a item at certain position in a list. x defines position at which the element will be added and y defines the element to be added in the list. And insert function takes exactly two arguments else it results in type error.

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

class P: 
   def __init__(self): 
      self.__x=100 
      self.y=200 
   def print(self): 
      print(self.__x, self.y)  
class C(P): 
   def __init__(self): 
      super().__init__() 
      self.__x=300 
      self.y=400  
d = C() 
d.print()

A - 300 400

B - 100 400

C - 100 200

D - 300 200

Answer : B

Explanation

In the above code x is a private variable declared in the class P. Thus value of x cannot be changed in the class C which inherits class P. But y is not a private variable thus its value can be changed.

Answer : C

Explanation

+ Operator cannot be operated on the sets.

Q 8 - Which event among them is fired when the right mouse button is released?

A - <ButtonReleased>

B - <ButtonPressed>

C - <ButtonReleased-3>

D - <ButtonPressed-3>

Answer : C

Explanation

It is the default way to do this kind of work.

Q 9 - Using the pack manager, how you can you put the components in a container in the same row?

A - Component.pack(side= ''LEFT'')

B - Component.pack(''Left '')

C - Component.pack(side=LEFT)

D - Component.pack(Left-side)

Answer : C

Explanation

It is the default way to do this.

Q 10 - Which module is used in python to create Graphics?

A - Turtle

B - Canvas

C - Tkinter

D - Graphics

Answer : A

python_questions_answers.htm
Advertisements