[go: up one dir, main page]

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 −

' ' 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 - 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 - 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 for − max(''please help '')

A - s

B - a blank space character

C - e

D - p

Answer : A

Explanation

python considers z as maximum value in the string and a blank space character as minimum value. So it goes like blank space, a to z as minimum to maximum.

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

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