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

A
B
=
AB
A=B
Error
None of the above

Explanation:
In the above code, the assign value for a = 13 and b = 15.

There are three conditions mentioned in the code:
1. print("A") if a > b , here 13 is not greater than 15 so condition becomes false
2. print("=") if a == b , here 13 is not equal to 15 so condition becomes false
3. else print("B"), condition 1 and 2 will not be true so program control will switch to else part and output will be "B".