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 −

'python ' [-3]?

A - 'o'

B - 't'

C - 'h'

D - Negative index error.

Answer : C

Explanation

Negative indexes begin toward the end of a string and go in reverse.

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 - How can we generate random numbers in python using methods?

A - random.uniform ()

B - random.randint()

C - random.random()

D - All of the above

Answer : D

Explanation

To generate random numbers we import random module and in that module we have these methods/functions.

uniform(x,y) returns a floating number in the range [x,y] random() returns a floating point number in the range [0, 1].

randint(x,y) returns a random integer number in the range [x, y].

Q 4 - What is output for − min(''hello world'')

A - e

B - a blank space character

C - w

D - None of the above.

Answer : B

Explanation

python considers a blank space character as minimum value in a string.

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.

Answer : B

Explanation

x is the object created by the constructor of the class Circle().

Answer : B, C, D.

Explanation

Recursive function is used to make the code simpler. They are better version of non-recursive functions.

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

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