Blog

6/recent/ticker-posts

Python Questions and Answers

General Python Quiz 2

Q 11 - What is output for −

raining'. find('z') ?

A ) Type error

B ) ' '

C ) -1

D ) Not found

Answer : C

Explanation

If the string is not found by method find() , it returns the integer -1.

Q 12 - 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 13 - Which operator is right-associative

A ) *

B ) =

C ) +

D ) %

Answer : B

Explanation

‘=‘ operator is right associative as assignment operators are right associative.

Q 14 - What is output of following code −

def func(x, ans):
   if(x==0):
      return 0
   else: 
      return func(x-1, x+ans) 
print(func(2,0))

A ) 0

B ) 1

C ) 2

D ) 3

Answer : A

Q 15 - What command is used to shuffle a list ‘L’?

A ) L.shuffle()

B ) random.shufflelist(L)

C ) shuffle(L)

D ) random.Shuffle(L)

Answer : D

Explanation

To shuffle the list we use random.shuffle(List_name) function.

Q 16 - 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!’

Answer : B

Explanation

The function ‘func’ will not run because it contains an exception. So in try and expect block. The function called under try will not run and will move to except block which defines the type of exception present in the function ‘func’. Thus block of statements present in except ZeroDivisionError is printed.

Q 17 - Which among them will produce {'a', 'b', 'c'}?

A ) Tuple(''abc'')

B ) List(''abc'')

C ) Set(''abac'')

D ) None of the above.

Answer : D

Explanation

Set does not allow the repetitive values in it and it separated each value present under a string.

Answer : B

Explanation

Checkbutton method is used to make a checkbox. In the parameters we need to pass the values as asked in the question. Here it should bind to v1 thus variable is set to v1 and frame should be under frame1 thus frame1 mentioned in the code.

Q 19 - Which way among them is used to create an event loop ?

A ) Window.eventloop()

B ) Window.mainloop()

C ) Window.loop()

D ) Eventloop.window()

Answer : B

Q 20 - What is the value of a, b, c in the given below code?

a, b = c = 2 + 2, ''SenGideons''

A ) a=4, 'SenGideons'

b= 4, 'SenGideons'

c= 4, 'SenGideons'

B ) a=2

b= 'SenGideons'

c=4, 'SenGideons'

C ) a=4

b= 'SenGideons'

c=4, 'SenGideons'

D ) a=4

b= 'SenGideons'

c= NULL.

Answer : C

python_questions_answers.html
Advertisements

Post a Comment

0 Comments

Ad Code

Responsive Advertisement

Hot Post