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 −

' ' in 'python' ?

A - 'python'

B - False

C - Name error

D - True

Answer : D

Explanation

To strings connected by in' operator gives true and false.

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 - Pylab is a package that combine _______,________&______ into a single namespace.

A - Numpy, scipy & matplotlib

B - Numpy, matplotlib & pandas

C - Numpy, pandas & matplotlib

D - Numpy, scipy & pandas

Answer : A

Explanation

pylab package in python combines numpy, scipy & matplotlib into a single namespace.

Q 4 - what is output of following code −

class Count:
   def __init__(self, count=0):
      self.__count=count
a=Count(2)
b=Count(2)
print(id(a)==id(b), end = '' '')

c= ''hello''
d= ''hello''
print(id(c)==id(d))

A - True False

B - False True

C - False False

D - True True

Answer : B

Explanation

The objects with same contents share the same object in the python library but this is not true for custom-defined immutable classes.

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.

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

class P: 
   def __init__(self): 
      self.__x=100 
      self.y=200 
   def print(self): 
      print(self.__x, self.y)  
class C(P): 
   def __init__(self): 
      super().__init__() 
      self.__x=300 
      self.y=400  
d = C() 
d.print()

A - 300 400

B - 100 400

C - 100 200

D - 300 200

Answer : B

Explanation

In the above code x is a private variable declared in the class P. Thus value of x cannot be changed in the class C which inherits class P. But y is not a private variable thus its value can be changed.

Answer : C

Explanation

+ Operator cannot be operated on the sets.

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