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 −

'Tutorials Point' [100:200]?

A - Index error.

B - ' '

C - 'Tutorials Point'

D - Syntax error

Answer : B

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 −

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

Answer : C

Explanation

+ Operator cannot be operated on the sets.

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

minidict = { 'name': 'TutorialsPoint', 'name': 'website'}
print(minidict['name'])

A - TutorialsPoint

B - Website

C - ('TutorialsPoint' , 'website')

D - It will show an Error.

Answer : B

Explanation

Dictionary gets updated by the above code as the key has been assigned a new value.

python_questions_answers.htm
Advertisements