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

Answer : B

Explanation

list are mutable whereas tuples are immutable i.e. in list changes can be made but in tuples it is not possible, they can only be operated its value cannot be changed.

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

Q 7 - Analyze the code −

print(''Recursive Function'') 
def factorial(n): 
   return(n*factorial(n-1))  
factorial(4)

A - Recursive Function 24.

B - Recursive Function.

C - Function runs infinitely and causes a StackOverflowError.

D - Syntax Error.

Answer : C

Explanation

there is no condition in the code to stop the function.

Q 8 - Select the correct function among them which can be used to write the data to perform for a binary output?

A - Write

B - Output.binary

C - Dump

D - Binary.output

Answer : C

Q 10 - Best part is you can display images in various options in Python. Select the option where you can display an image −

A - Only A label

B - Only A button and A label

C - Only A checkbox

D - A label, a check box , a button and a radio button.

Answer : D

python_questions_answers.htm
Advertisements