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

a = (1, 2)
a[0] +=1

A - (1,1,2)

B - 2

C - Type Error

D - Syntax Error

Answer : C

Explanation

TypeError − ‘tuple' object does not support item assignment because a tuple is immutable.

Q 3 - Name the error that doesn't cause program to stop/end, but the output is not the desired result or is incorrect.

A - Syntax error

B - Runtime error

C - Logical error

D - All of the above

Answer : C

Explanation

logical error doesn't cause the program to stop/end, but the output is not the desired result or is incorrect.

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 will be the output of the following code?

def total(initial = 5, *num, **key):
   count = initial
   for n in num:
      count+=n
   for k in key:
      count+=key[k]
   return count
print(total(100,2,3, clouds=50, stars=100))

A - 260

B - 160

C - 155

D - 255

Answer : D

Explanation

It takes initial value as 100 now. And adds 2, 3, 50 and 100 to it as according to code.

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

eval(''1 + 3 * 2'')

A - ‘1+6'

B - ‘4*2'

C - ‘1+3*2'

D - 7

Answer : D

Explanation

Eval is a method used to evaluate the values entered in the braces.

Q 7 - What is the out of the code?

def rev_func(x,length): 
   print(x[length-1],end='' '') 
   rev_func(x,length-1) 
x=[11, 12, 13, 14, 15] 
rev_func(x,5) 

A - The program runs fine without error.

B - Program displays 15 14 13 12 11.

C - Program displays 11 12 13 14 15.

D - Program displays 15 14 13 12 11 and then raises an index out of range exception.

Answer : D

Explanation

In the print statement of rev_func we use the index value of list x. We decrement the value of length of function because it becomes the index of x in the print statement.

Q 8 - Which among them is incorrect for set s={100,101,102,103}

A - Len(s)

B - Sum(s)

C - Print(s[3])

D - Max(s)

Answer : C

Explanation

There is no indexing in Sets.

Q 9 - Suppose you are using a grid manager then which option is best suitable to place a component in multiple rows and columns?

A - Columnspan and rowspan

B - Only row

C - Only column

D - Only rowspan

Answer : A

Q 10 - What will be the output of the following code?

print(type(1/2))

A - <class 'float'>

B - <class 'int'>

C - NameError: ‘½' is not defined.

D - 0.5

Answer : A

Explanation

Output of ½ is 0.5.

python_questions_answers.htm
Advertisements