Explanations "Top Python Quiz Questions"
350 subscribers
80 photos
1 link
Explanations "Top Python Quiz Questions"
Download Telegram
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.
What is the result of the code snippet?

2
3
'2'
'1'
KeyError
None of the above

Explanation:
Simple key-value pair is used recursively, D[1] = 1, str(1) = ‘1’.
So, D[str(D[1])] = D[‘1’] = 2, D[2] = ‘2’ and D[‘2’] = 3.
What is the output of the code snippet?

pYtHoN PrOgRaMmInG
Python Programming
python programming
PYTHON PROGRAMMING
Error
None of the above

Explanation:
In this code snippet, we convert every element in odd index to lower case and every element in even index to uppercase.