What will be the output of the following Python expression?
~100?
a) 101
b) -101
c) 100
d) -100
Explanation: Suppose we have an expression ~A. This is evaluated as: -A – 1. Therefore, the expression ~100 is evaluated as -100 – 1, which is equal to -101.
What will be the output of the following Python code snippet?
['hello', 'morning'][bool('')]
a) error
b) no output
c) hello
d) morning
Explanation: The line of code shown above can be simplified to state that ‘hello’ should be printed if the argument passed to the Boolean function amounts to zero, else ‘morning’ will be printed.
What will be the output of the following Python code?
['f', 't'][bool('spam')]
a) t
b) f
c) No output
d) Error
Explanation: The line of code can be translated to state that ‘f’ is printed if the argument passed to the Boolean function amount to zero. Else ‘t’ is printed. The argument given to the Boolean function in the above case is ‘spam’, which does not amount to zero. Hence the output is t.