What is the output of the following Python code? print(-2 ** 2)
Correct answer A. -4
Explanation
The power operator binds more tightly than a unary minus on its left, so -2 ** 2 means -(2 ** 2), which is -4. To square negative two you must write (-2) ** 2, which gives 4. The language reference states that ** binds less tightly than a unary operator on its right but more tightly than one on its left.
Answer checked How we write and check questions
Discussion