Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

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 −

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 - Syntax error in python is detected by _________at _______

A - compiler/ compile time

B - interpreter/ run time

C - compiler/ run time

D - interpreter/ compile time

Answer : B

Explanation

Syntax error in python is detected by interpreter at run time.

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

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

Explanation

You need to define the format in which you want to open the file. Proper path has to be declared by the user for the interpreter to reach the destination of the file.

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