Explanations "Top Python Quiz Questions"
349 subscribers
80 photos
1 link
Explanations "Top Python Quiz Questions"
Download Telegram
What is the output of the program?

Specific ZeroDivisionError Specific ZeroDivisionError
Specific ZeroDivisionError Finally ZeroDivisionError
Specific IndexError General IndexError Finally ZeroDivisionError
Finally IndexError Specific ZeroDivisionError Finally ZeroDivisionError
Finally IndexError Specific ZeroDivisionError General ZeroDivisionError Finally ZeroDivisionError
Finally IndexError Specific ZeroDivisionError
None of the above

Explanation:
"finally" block of code is always executed whether the exception occurs or not. If exception occurs, the except block is executed first matched by exception type.

General try and except concept:
First try clause is executed i.e. the code between try and except clause.
If there is no exception, then only try clause will run, except clause will not get executed.
If any exception occurs, the try clause will be skipped and except clause will run.
If any exception occurs, but the except clause within the code doesn’t handle it, it is passed on to the outer try statements. If the exception is left unhandled, then the execution stops.
A try statement can have more than one except clause.
What is the output of the code?

['top', 'quiz']
['TOP', 'QUIZ']
['top', 'quiz', 'TOP', 'QUIZ']
[None, None]
[]
None of the above

Explanation:
The loop does not terminate and will run without end because new elements are being added to the list in each iteration.
What will be the output of the code snippet?

[[], 'abc', [0], 1, 0]
['abc', [0], 1]
['abc', 0, 1]
[0, 1]
[1]
['abc']
None of the above

Explanation:
The above code filters all the elements from list a, which evaluates to boolean value true, i.e. any non empty string, list or non-zero value is accepted.
What will be the value of 'result'?

[1, 3, 5, 7, 8]
[1, 7, 8]
[1, 2, 4, 7, 8]
Error
None of the above

Explanation:
Here, 'result' is a list which is extending three times. When first time 'extend' function is called for 'result', the inner code generates a generator object, which is further used in 'extend' function. This generator object contains the values which are in 'list1' only (not in 'list2' and 'list3'). Same is happening in second and third call of 'extend' function in these generator object contains values only in 'list2' and 'list3' respectively. So, 'result' variable will contain elements which are only in one list (not more than 1 list).
What will be the output of the code?

12
52
13
60
Error
None of the above

Explanation:
In the above code, obj.quantity has been initialised to 10. There are a total of three items in the dictionary, price, quantity and bags. Hence, len(obj.__dict__) is 3.
What will be the output of the code?

Exception is thrown
Count.test=25, k=25
Count.test=25, k=0
Count.test=0, k=0
None of the above

Explanation:
The program has no error. Here, test is a member of the class while k isn’t. Hence test keeps getting incremented 25 time while k remains 0.
What will be the result of the code?

[[1, 2], [3, 4], [5, 6]]
[[1, 2], [3, 4]]
[(1, 3, 5), (2, 4, 6)]
[1, 2, 3, 4, 5, 6]
Error
None of the above

Explanation:
The code uses a zip function to transpose the given matrix.
Zip is a built-in function that extracts data from the different columns and changes it into tuples. The zip() function returns a zip object, which is an iterator of tuples where the first item in each passed iterator is paired together, and then the second item in each passed iterator are paired together etc. If the passed iterators have different lengths, the iterator with the least items decides the length of the new iterator.