Search for question
Question

Q2.2.2 The operators listed in Table 2.1 are all binary operators: they take two operands (numbers) and return a single value. The symbol is also used as a unary operator, which returns the negative value of the single operand on which it acts. For example, >>> a = 4 >>> b = -a >>> b -4 == Note that the expression b = -a (which sets the variable b to the negative value of a) is different from the expression b = a (which subtracts a from b and stores the result in b). The unary operator has a higher precedence than *, / and % but a lower precedence than exponentiation (**), so that, for example -2 ** 4 is -16 (i.e. —(24), not (-2)4). Predict the result of the following expressions and check them using the Python shell. (a) -2 ** 2 (b) 2 ** -2 (c) -2 ** -2 (d) ** 2 2 ** 3 (e) 2 ** 3 ** 2 (f) -2 ** 3 ** 2

Fig: 1