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 - Which is invalid in python for z = 5 ?

A - z = z++

B - z = ++z

C - z += 1

D - z -= 1

Answer : A

Explanation

z = z++ is not valid in python, it is not a legal expression. It results in syntax error.

Q 3 - Select the option for following code −

s = 0
for d in range(0, 5, 0.1):
… s += d
… print(s)

A - Syntax Error

B - Type Error

C - Runtime Error

D - Both b & c

Answer : D

Explanation

we will get type error during runtime as float object cannot be interpreted as integer. Here 0.1 is the float value.

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 is the output of the code?

def f():
   global z
   print('z is: ', z)
   z=50
   print('new value of global z is: ', z)

f()
   print('Value of z is: ', z)

A - z is 100

new value of global z is: 100

value of z is 100

B - z is 100

new value of global z is: 100

value of z is 50

C - z is 100

new value of global z is: 50

value of z is 100

D - z is 100

new value of global z is: 50

value of z is 50

Answer : D

Explanation

Here in the above code ‘global' keyword is used to state that ‘z' is global variable. So when we assign a value to z in the function then the new assigned value is reflected whenever we use the value of ‘z' in the main block or outside the function.

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

s = ''\t\t\t\n\nTutorialsPoint\n\n\n\t\t\t''
s.strip()

A - '\n\nTutorialsPoint\n\n\n'

B - '\t\t\tTutorialsPoint\t\t\t'

C - 'TutorialsPoint'

D - 'TutorialsPoint' , '\t\t\t\n\n \n\n\n\t\t\t'

Answer : C

Explanation

Strip method is used to remove all the newline and tab spaces code in the string.

Q 7 - Which of the function among will return 4 on the set s = {3, 4, 1, 2}?

A - Sum(s)

B - Len(s)

C - Max(s)

D - Four(s)

Answer : B & C.

Explanation

len(s) returns the length of the set and max(s) returns the maximum value in the set.

Answer : C

Explanation

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

Q 9 - In Python we can create a popup menu. Select the code to display a popup menu?

A - Menu.post(250,250)

B - Menu.post()

C - Menu.display()

D - Menu.display_popup(250,250)

Answer : A

Q 10 - Which can be an Identifier among them in Python?

A - 1abc

B - $12a

C - _xy1

D - @python

Answer : C

Explanation

Because Identifiers start from letter A to Z or a to z or an underscore (_) followed by more letters or zero or underscores and digits (0 to 9). Python does not allow @ or $ or % within the identifier.

python_questions_answers.htm
Advertisements