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

x = 2
y = 10
x * = y * x + 1

A - 42

B - 41

C - 40

D - 39

Answer : A

Explanation

x * = y * x + 1 means x = x * (y * x + 1)

Q 3 - What is output of following code −

print('hijk'.partition('ab'))

A - ('hijk', 'cd', ' ')

B - ('hijk')

C - ('hijk', ' ', ' ')

D - Name error

Answer : C

Explanation

Since there are no separators in the given string so the output is the same string.

Q 4 - What is output of following code −

def func(n):
   if(n==1):
      return 1;
   else:
      return(n+func(n-1))
print(func(4))

A - 12

B - 10

C - 9

D - 11

Answer : B

Q 5 - What command is used to shuffle a list ‘L’?

A - L.shuffle()

B - random.shufflelist(L)

C - shuffle(L)

D - random.Shuffle(L)

Answer : D

Explanation

To shuffle the list we use random.shuffle(List_name) function.

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.

Q 7 - Suppose you are given a set(s1={1,2,3}) then what is the output for the code −

2 * s1?

A - (1,1,2,2,3,3)

B - [1,1,2,2,3,3]

C - Illegal

D - (1,2,3,1,2,3)

Answer : C

Explanation

* cannot be operated on the sets.

Answer : C

Explanation

Frame() method is used to make a frame in python.

Answer : C

Q 10 - Which is the special symbol used in python to add comments?

A - $

B - //

C - /*.... */

D - #

Answer : D

python_questions_answers.htm
Advertisements