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 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

Q 3 - Select the option for following code −

s = 0
for d in range(0, 5, 0.1):
 s += d
 print(s)

A - Syntax Error

B - Type Error

C - Runtime Error

D - Both b & c

Answer : D

Explanation

we will get type error during runtime as float object cannot be interpreted as integer. Here 0.1 is the float value.

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 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 - Analyze the given below code?

class Demo: 
   def __init__(self,d): 
      self.d=d 
   def print(self): 
      print(d)  
a = Demo(''Hello'') 
a.print()

A - You cannot use print(self) as a function name.

B - Program has an error because class A does not have a constructor.

C - Program will print Hello' if we change print(d) to print(self.d).

D - Syntax Error.

Answer : C

Explanation

D stores the argument value here. Thus when we call the class Hello'' is passed as an argument which is stored in the variable d.

Answer : B, C, D.

Explanation

Recursive function is used to make the code simpler. They are better version of non-recursive functions.

Answer : C

Explanation

Frame() method is used to make a frame in python.

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 is the special symbol used in python to add comments?

A - $

B - //

C - /*.... */

D - #

Answer : D

python_questions_answers.htm
Advertisements