Python Quiz - Quiz Questions - 22 May, 2023



Title: Python Quiz

Reading Time: 5 Minutes

Published Time: 22 May, 2023



Q 1 - What is output for −

a = ['hat', 'mat', 'rat']

'rhyme'.join(a)

A - [‘hat’,’mat’,’rat’,’rhyme’]

B - ‘hatmatratrhyme’

C - [‘hat mat rat rhyme’]

D - ‘hatrhymematrhyme rat’

 Show Answer

Q 2 - Which is invalid in python for z = 5 ?

A - z = z++

B - z = ++z

C - z += 1

D - z -= 1

 Show Answer

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

 Show Answer

Q 4 - what is output of following code −

class Count:
   def __init__(self, count=0):
      self.__count=count
a=Count(2)
b=Count(2)
print(id(a)==id(b), end = '' '')

c= ''hello''
d= ''hello''
print(id(c)==id(d))

A - True False

B - False True

C - False False

D - True True

 Show Answer

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

def nprint(message, n):
while(n > 0):
   print(message)
n-=1
nprint('z', 5)

A - zzzz

B - zzzzz

C - Syntax Error

D - Infinite Loop

 Show Answer

Q 6 - Guess the output −

def main(): 
   try: 
      func() 
      print(''print this after function call'') 
   except ZeroDivisionError: 
      print('Divided By Zero! Not Possible! ') 
   except: 
      print('Its an Exception!') 
def func(): 
   print(1/0) 
main()

A - ‘Its an Exception!’

B - ‘Divided By Zero! Not possible!’

C - ‘print this after function call’ followed by ‘Divided By Zero! Not Possible!’

D - ‘print this after function call’ followed by ‘Its an Exception!’

 Show Answer

Q 7 - Which among them is correct(s) about Recursive Function?

A - They are much faster than the normal functions.

B - They take more space then the non-recursive functions.

C - They can always be replaced by non-recursive functions.

D - Using recursive functions however also gives a natural and straight forward simple solution for the program.

 Show Answer

Q 8 - Which code is used to open a file for binary writing?

A - ''w''

B - ''wb''

C - ''r+''

D - ''a''

 Show Answer

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

 Show Answer

Q 10 - Which is the special symbol used in python to add comments?

A - $

B - //

C - /*.... */

D - #

Grab the best assignment now!

PLACE AN ORDER

24*7SUPPORT

Tap to ChatGet Assistance