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

y = [4, 5,1j]
y.sort()

A - [1j,4,5]

B - [5,4,1j]

C - [4,5,1j]

D - Type Error

Answer : D

Explanation

we cannot compare complex numbers with numbers, so the output results in type error stating that complex numbers cannot be compared with <,>,=.

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 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 happens in the below code?

class A: 
   def __init__(self, i=100): 
      self.i=i 
class B(A): 
   def __init__(self,j=0): 
      self.j=j 
def main(): 
   b= B() 
   print(b.i) 
   print(b.j) 
main() 

A - Class B inherits all the data fields of class A.

B - Class B needs an Argument.

C - The data field j' cannot be accessed by object b.

D - Class B is inheriting class A but the data field i' in A cannot be inherited.

Answer : D

Explanation

Reason being that i is initiated with self thus making it a instantiate variable of that class which cannot be inherited by the above way.

Q 7 - Which options are correct to create an empty set in Python?

A - {}

B - ()

C - []

D - set()

Answer : D

Explanation

we need to define the set by including the keyword set'.

Q 8 - Select the correct function among them which can be used to write the data to perform for a binary output?

A - Write

B - Output.binary

C - Dump

D - Binary.output

Answer : C

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 - How you can lift the pen of in turtle?

A - Turtle.lift()

B - Turtle.liftup()

C - Turtle.penup()

D - Turtle.up()

Answer : C

python_questions_answers.htm
Advertisements