Python Online Quiz


Advertisements

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 - What is output of following code −

num=3
while True:
   if (num%0o12 == 0):
      break
print(num)
num += 1

A - 3 4 5 6 7 8 9 10 11 12

B - 3 4 5 6 7 8 9

C - 3 4 5 6 7 8 9 10 11

D - None of the above

Answer : B

Explanation

we are getting output 3 to 9 because 0o12 is octal number.

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

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 - What happens in the below code?

class A: 
   def __init__(self, i=100): 
      self.i=i 
class B(A): 
   def __init__(self,j=0): 
      self.j=j 
def main(): 
   b= B() 
   print(b.i) 
   print(b.j) 
main() 

A - Class B inherits all the data fields of class A.

B - Class B needs an Argument.

C - The data field ‘j’ cannot be accessed by object b.

D - Class B is inheriting class A but the data field ‘i’ in A cannot be inherited.

Answer : D

Explanation

Reason being that i is initiated with self thus making it a instantiate variable of that class which cannot be inherited by the above way.

Q 8 - Which method is used to convert raw byte data to a string?

A - Encode()

B - Decode()

C - Convert()

D - tostring()

Answer : B

Explanation

Decode is the method used to convert the raw byte data to a string.

Q 9 - Which way among them is used to create an event loop ?

A - Window.eventloop()

B - Window.mainloop()

C - Window.loop()

D - Eventloop.window()

Answer : B

Q 10 - What is the value of a, b, c in the given below code?

a, b = c = 2 + 2, ''TutorialsPoint''

A - a=4, 'TutorialsPoint'

b= 4, 'TutorialsPoint'

c= 4, 'TutorialsPoint'

B - a=2

b= 'TutorialsPoint'

c=4, 'TutorialsPoint'

C - a=4

b= 'TutorialsPoint'

c=4, 'TutorialsPoint'

D - a=4

b= 'TutorialsPoint'

c= NULL.

Answer : C

python_questions_answers.htm
Advertisements