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 the output for −

'you are doing well' [2:999]

A - 'you are doing well'

B - ' '

C - Index error.

D - 'u are doing well'

Answer : D

Explanation

Slicing will never give us an error even if we give it too large of an index for the string. It will just return the widest matching slice it can.

Q 2 - How can we swap two numbers a = 10, b = 20 in python without using third variable?

A - a = b

b = a

B - a,b = b,a

C - both a & b

D - b = a

a = b

Answer : C

Explanation

To swap two numbers we can use both a & b option. Both a & b are similar statemnts written in different ways.

Q 3 - Which operator is right-associative

A - *

B - =

C - +

D - %

Answer : B

Explanation

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

Answer : B

Explanation

If A is proper subset of B then hen all elements of A are in B but B contains at least one element that is not in B.

Q 5 - What is output of following code −

l = [1,2,6,5,7,8]
l.insert(9)

A - l=[9,1,2,6,5,7,8]

B - l=[1,2,6,5,9.7,8] (insert randomly at any position)

C - l=[1,2,6,5,7,8,9]

D - Type Error

Answer : D

Explanation

listname.insert(x,y) method is used to insert a item at certain position in a list. x defines position at which the element will be added and y defines the element to be added in the list. And insert function takes exactly two arguments else it results in type error.

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 among them will produce {'a', 'b', 'c'}?

A - Tuple(''abc'')

B - List(''abc'')

C - Set(''abac'')

D - None of the above.

Answer : D

Explanation

Set does not allow the repetitive values in it and it separated each value present under a string.

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 - Which is the special symbol used in python to add comments?

A - $

B - //

C - /*.... */

D - #

Answer : D

python_questions_answers.htm
Advertisements