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 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 the output of following code −

[ (a,b) for a in range(3) for b in range(a) ]

A - [ (1,0),(2,1),(3,2)]

B - [ (0,0),(1,1),(2,2)]

C - [(1,0),(2,1),(2,1)]

D - [ (1,0),(2,0),(2,1)]

Answer : D

Explanation

This is nested for loop. The output of first for loop will be the value for the next loop.

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.

Answer : C

Explanation

since there is no such element in the set, so key error is raised.

Q 5 - What is the output of the code?

def f():
   global z
   print('z is: ', z)
   z=50
   print('new value of global z is: ', z)

f()
   print('Value of z is: ', z)

A - z is 100

new value of global z is: 100

value of z is 100

B - z is 100

new value of global z is: 100

value of z is 50

C - z is 100

new value of global z is: 50

value of z is 100

D - z is 100

new value of global z is: 50

value of z is 50

Answer : D

Explanation

Here in the above code ‘global’ keyword is used to state that ‘z’ is global variable. So when we assign a value to z in the function then the new assigned value is reflected whenever we use the value of ‘z’ in the main block or outside the function.

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.

Q 7 - Which options are correct to create an empty set in Python?

A - {}

B - ()

C - []

D - set()

Answer : D

Explanation

we need to define the set by including the keyword ‘set’.

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.

Answer : C

Explanation

Button keyword is used to make a button in Python. To set the process button in command we assign the value processButton in the command. Any text value can be given to the button which is assigned under text keyword.

Q 10 - Which is the special symbol used in python to add comments?

A - $

B - //

C - /*.... */

D - #

Answer : D


python_questions_answers.htm

Advertisements