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

Nothing
Inbox Inbox
Inbox Spam
Spam Inbox
Spam Spam
Error
None of the above

Explanation:
The output in this case is again 'Inbox' on one line and 'Spam' on another, because the print statement in the nested function finds the name in the enclosing function’s local scope, and the print at the end finds the variable in the global scope.
What will be the output of the code?

The program has an error because there isn’t any function to return self.a
The program has an error because b is private and display(self) is returning a private member
The program has an error because b is private and hence can’t be printed
The program runs fine and 1 is printed

Explanation:
Variables beginning with two underscores are said to be private members of the class and they can’t be accessed directly.
What is the output of the program?

['a', 'b', 'c']
['c', 'b', 'a']
['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']
['c', 'b', 'a', 'c', 'b', 'a', 'c', 'b', 'a']
[]
Error
None of the mentioned

Explanation:
A expression list[listelements]*N where N is a integer appends N copies of list elements in the original list. If N is a negative integer or 0 output will be a empty list else if N is positive list elements will be added N times to the original list.
What is the true statement about the code snippet?

Class B inherits all the data fields of class A
Class B needs an argument
The data field ‘j’ cannot be accessed by object b
Class B is inheriting class A but the data field ‘i’ in A cannot be inherited

Explanation:
Program ends with error 'B' object has no attribute 'i'.
Reason being that i is initiated with self thus making it a instantiate variable of that class which cannot be inherited by the above way.
What is the output of the code?

{0: 1, 7: 0, 1: 1, 8: 0}
{1: 1, 7: 2, 0: 1, 8: 1}
{0: 0, 7: 0, 1: 1, 8: 1}
KeyError

Explanation:
enumerate() will return a tuple, the loop will have x = (0, 0), (1, 1). Thus D[0] = 0, D[1] = 1, D[0 + 7] = D[7] = 0 and D[1 + 7] = D[8] = 1.
Note:
Dictionary is unordered, so the sequence of the key-value pair may differ in each output.
What is the output of the program?

0-0-5
1-2-10
2-1-5
2-0-5
3-1-10
3-2-6
Error

Explanation:
First off, the * and % have the same operator precedence, so the expression is evaluated from left to right unless parentheses are present. The first expression evaluates to 8 % 3, which leaves a remainder of 2. The second expression is just evaluated left to right since * and % have the same operator precedence, and it reduces to 6 % 3, which is 0. The last expression reduces to 5 * 1, which is 5. Therefore, the output on line 6 is 2-0-5.
What is the output of the code snippet?

False False True True False
False False True True True
True True True True True
True True True True False
True True 0 0 False
True True 3 1 False
True True 3 1 True
Error
None of the above

Explanation:
True: This keyword is used to represent a boolean true. If a statement is true, “True” is printed.
False: This keyword is used to represent a boolean false. If a statement is false, “False” is printed.
None: This is a special constant used to denote a null value or a void. It’s important to remember, 0, any empty container(e.g empty list) does not compute to None.
It is an object of its datatype – NoneType. It is not possible to create multiple None objects and can assign them to variables.
Additionally, in Python, True == 1 and False == 0, as True and False are type bool, which is a subtype of int. When you use the operator +, it is implicitly adding the integer values of True and False.
That's why True + True + True = 1 + 1 + 1 = 3 and True + False + False = 1 + 0 + 0 = 1.