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

x = 2
y = 10
x * = y * x + 1

A - 42

B - 41

C - 40

D - 39

Answer : A

Explanation

x * = y * x + 1 means x = x * (y * x + 1)

Q 3 - Which operator is right-associative

A - *

B - =

C - +

D - %

Answer : B

Explanation

= operator is right associative as assignment operators are right associative.

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 −

print('any'.encode())

A - any'

B - yan'

C - b'any'

D - x'any'

Answer : C

Explanation

encode() returns bytes object.

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 : B, C, D.

Explanation

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

Q 8 - Which function can be used on the file to display a dialog for saving a file?

A - Filename = savefilename()

B - Filename = asksavefilename()

C - Fielname = asksaveasfilename()

D - No such option in python.

Answer : C

Explanation

This is the default method to display a dialog for saving a file in Tkinter module of Python.

Answer : B

Explanation

Text is created in the canvas by using create_text method of canvas. Color of the text can be set according to the user which is specified under filled'.

python_questions_answers.htm
Advertisements