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 −

a = ['he', 'she', 'we']

' '.join(a)

A - ['heshewe']

B - 'heshewe'

C - ['he she we']

D - 'he she we'

Answer : B

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

def func(x, ans):
   if(x==0):
      return 0
   else: 
      return func(x-1, x+ans) 
print(func(2,0))

A - 0

B - 1

C - 2

D - 3

Answer : A

Q 5 - What is the output of the following code?

import math
 
   def main():
      math.cos(math.pi)
main()
   print(main())

A - -1

B - None

C - Error

D - Math.pi not defined

Answer : B

Explanation

None is printed because function does not return the value.

Q 6 - Which among them is used to create an object?

A - A class

B - A function

C - A method

D - A constructor

Answer : D

Explanation

constructor is used to create an object of class.

Q 7 - Analyze the code −

print(''Recursive Function'') 
def factorial(n): 
   return(n*factorial(n-1))  
factorial(4)

A - Recursive Function 24.

B - Recursive Function.

C - Function runs infinitely and causes a StackOverflowError.

D - Syntax Error.

Answer : C

Explanation

there is no condition in the code to stop the function.

Answer : C

Explanation

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

Answer : C

Q 10 - Which module is used in python to create Graphics?

A - Turtle

B - Canvas

C - Tkinter

D - Graphics

Answer : A

python_questions_answers.htm
Advertisements