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 −

'search'. find('S') ?

A - s

B - -1

C -

D - None of the above

Answer : B

Explanation

The method find() is case sensitive.

Q 2 - What is output for following code −

y = [4, 5,1j]
y.sort()

A - [1j,4,5]

B - [5,4,1j]

C - [4,5,1j]

D - Type Error

Answer : D

Explanation

we cannot compare complex numbers with numbers, so the output results in type error stating that complex numbers cannot be compared with <,>,=.

Q 3 - When the given code is executed how many times ' 'you are learning python ' ' will be printed.

a = 0
while a<10:
 print(''you are learning python'')
 pass

A - 9

B - 10

C - 11

D - Infinite number of times.

Answer : D

Explanation

The loop will execute infinite number of times because there is no statement specified for end of loop and pass indicates nothing is to be done.

Q 4 - What is output of following code −

s = ''mnopqr ''
i = ''m ''
while i in s:
   print('i', end= '' '')

A - i i i i i i i i..

B - m m m m m ..

C - m n o p q r

D - no output

Answer : A

Q 5 - What is the output of the code?

def f():
   global z
   print('z is: ', z)
   z=50
   print('new value of global z is: ', z)

f()
   print('Value of z is: ', z)

A - z is 100

new value of global z is: 100

value of z is 100

B - z is 100

new value of global z is: 100

value of z is 50

C - z is 100

new value of global z is: 50

value of z is 100

D - z is 100

new value of global z is: 50

value of z is 50

Answer : D

Explanation

Here in the above code global' keyword is used to state that z' is global variable. So when we assign a value to z in the function then the new assigned value is reflected whenever we use the value of z' in the main block or outside the function.

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.

Answer : B, C, D.

Explanation

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

Answer : D

Explanation

You need to define the format in which you want to open the file. Proper path has to be declared by the user for the interpreter to reach the destination of the file.

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

python_questions_answers.htm
Advertisements