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 −

'Tutorials Point' [100:200]?

A - Index error.

B - ' '

C - 'Tutorials Point'

D - Syntax error

Answer : B

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 - Name the python module which supports regular expressions.

A - regex

B - re

C - pyre

D - pyregex

Answer : B

Explanation

re is the module which supports regular expressions and is part of standard library.

We can import re module as − import re.

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 - How can we check whether the object is instance of class or not. Let us consider an object O which is instance of class B.

A - B.isinstance(O)

B - O.isinstance(B)

C - isinstance(O,B)

D - isinstance(B,O)

Answer : C

Explanation

isinstance() method is used to find whether the object is instance of class or not.

Q 5 - What command is used to shuffle a list L'?

A - L.shuffle()

B - random.shufflelist(L)

C - shuffle(L)

D - random.Shuffle(L)

Answer : D

Explanation

To shuffle the list we use random.shuffle(List_name) function.

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

eval(''1 + 3 * 2'')

A - 1+6'

B - 4*2'

C - 1+3*2'

D - 7

Answer : D

Explanation

Eval is a method used to evaluate the values entered in the braces.

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 9 - Select the correct option to draw a rectangle centred at 50,50 with width and height as 50, 70 respectively.

A - Canvas.create_rect(50,50,50,70)

B - Canvas.create_rect(50,70,50,50)

C - Canvas.create_rectangle(50,50,50,70)

D - Tkinter.create_rect(50,50,50,70)

Answer : C

Q 10 - What will be the output of the following code?

minidict = { 'name': 'TutorialsPoint', 'name': 'website'}
print(minidict['name'])

A - TutorialsPoint

B - Website

C - ('TutorialsPoint' , 'website')

D - It will show an Error.

Answer : B

Explanation

Dictionary gets updated by the above code as the key has been assigned a new value.

python_questions_answers.htm
Advertisements