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 output for −

'search'. find('S') ?

A - s

B - -1

C -

D - None of the above

Answer : B

Explanation

The method find() is case sensitive.

Q 2 - What is output of following code −

a = (1, 2)
a[0] +=1

A - (1,1,2)

B - 2

C - Type Error

D - Syntax Error

Answer : C

Explanation

TypeError − tuple' object does not support item assignment because a tuple is immutable.

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.

Answer : B

Explanation

If A is proper subset of B then hen all elements of A are in B but B contains at least one element that is not in B.

Q 5 - What command is used to shuffle a list L'?

A - L.shuffle()

B - random.shufflelist(L)

C - shuffle(L)

D - random.Shuffle(L)

Answer : D

Explanation

To shuffle the list we use random.shuffle(List_name) function.

Q 6 - What happens in the below code?

class A: 
   def __init__(self, i=100): 
      self.i=i 
class B(A): 
   def __init__(self,j=0): 
      self.j=j 
def main(): 
   b= B() 
   print(b.i) 
   print(b.j) 
main() 

A - Class B inherits all the data fields of class A.

B - Class B needs an Argument.

C - The data field j' cannot be accessed by object b.

D - Class B is inheriting class A but the data field i' in A cannot be inherited.

Answer : D

Explanation

Reason being that i is initiated with self thus making it a instantiate variable of that class which cannot be inherited by the above way.

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 - What will be the output of the following code?

print(type(1/2))

A - <class 'float'>

B - <class 'int'>

C - NameError: ' is not defined.

D - 0.5

Answer : A

Explanation

Output of is 0.5.

python_questions_answers.htm
Advertisements