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 −

a = ['hat', 'mat', 'rat']

'rhyme'.join(a)

A - [‘hat','mat','rat','rhyme']

B - ‘hatmatratrhyme'

C - [‘hat mat rat rhyme']

D - ‘hatrhymematrhyme rat'

Answer : D

Explanation

The method join() takes list of string as input and returns string as output. It removes ‘,' and add the given string with join to the list.

Q 2 - Which is invalid in python for z = 5 ?

A - z = z++

B - z = ++z

C - z += 1

D - z -= 1

Answer : A

Explanation

z = z++ is not valid in python, it is not a legal expression. It results in syntax error.

Q 3 - What is output of following code −

print('hijk'.partition('ab'))

A - ('hijk', 'cd', ' ')

B - ('hijk')

C - ('hijk', ' ', ' ')

D - Name error

Answer : C

Explanation

Since there are no separators in the given string so the output is the same string.

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.

Q 6 - What is the output of the code?

try: 
   list = 5*[0]+5*[10] 
   x = list[9] 
   print(''Done!'') 
except IndexError: 
   print(''Index out of Bond! '') 
else: 
   print(''Nothing is wrong!'') 
finally: 
   print(''Finally block!'') 

A - ‘Finally Block!'

B - ‘Done!' follow by ‘Nothing is wrong!'

C - ‘Nothing is wrong!' followed by ‘Finally block!'

D - ‘Done!' follow by ‘Nothing is wrong!' followed by ‘Finally block'.

Answer : D

Explanation

In the above Try block we make a list of total 10 elements by adding 5 times zero and 5 times 10. Thus when we try to find out the element at index 9 no error is raised by Python.

Answer : C

Explanation

+ Operator cannot be operated on the sets.

Answer : B

Explanation

Checkbutton method is used to make a checkbox. In the parameters we need to pass the values as asked in the question. Here it should bind to v1 thus variable is set to v1 and frame should be under frame1 thus frame1 mentioned in the code.

Q 9 - Which way among them is used to create an event loop ?

A - Window.eventloop()

B - Window.mainloop()

C - Window.loop()

D - Eventloop.window()

Answer : B

Q 10 - What will be the output of the following code?

minidict = { 'name': 'TutorialsPoint', 'name': 'website'}
print(minidict['name'])

A - TutorialsPoint

B - Website

C - ('TutorialsPoint' , 'website')

D - It will show an Error.

Answer : B

Explanation

Dictionary gets updated by the above code as the key has been assigned a new value.

python_questions_answers.htm
Advertisements