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 −

' ' in 'python' ?

A - 'python'

B - False

C - Name error

D - True

Answer : D

Explanation

To strings connected by ‘in’ operator gives true and false.

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

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 - Find the output of the code?

def f(a, b = 1, c = 2):
   print('a is: ',a, 'b is: ', b, 'c is: ', c)
f(2, c = 2)
f(c = 100, a = 110)

A - a is: 2 b is: 1 c is: 2

a is: 110 b is: 1 c is: 100

B - a is: 2 b is: 2 c is: 2

a is: 110 b is: 2 c is: 100

C - a is: 0 b is: 2 c is: 2

a is: 110 b is: 0 c is: 100

D - a is: 110 b is: 0 c is: 100

a is: 110 b is: 0 c is: 100

Answer : A

Explanation

Value of Arguments is passed to the parameters in order of their sequence.

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 - Which of the function among will return 4 on the set s = {3, 4, 1, 2}?

A - Sum(s)

B - Len(s)

C - Max(s)

D - Four(s)

Answer : B & C.

Explanation

len(s) returns the length of the set and max(s) returns the maximum value in the set.

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.

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

Q 10 - How you can lift the pen of in turtle?

A - Turtle.lift()

B - Turtle.liftup()

C - Turtle.penup()

D - Turtle.up()

Answer : C

python_questions_answers.htm
Advertisements