Practice mode Python

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.