?
What is the result of 5 - 2 + 1 ?
Answer & Solution
Correct Answer:
Option
B
In Python, operators have specific precedence levels that determine the order in which operations are performed.
Subtraction (-) and addition (+) operators have the same precedence level and are evaluated from left to right (left associativity).
In the expression 5 - 2 + 1:
First, 5 - 2 is evaluated, resulting in 3.
Then, 3 + 1 is evaluated, resulting in 4.
Thus, the result of the expression 5 - 2 + 1 is 4.
Subtraction (-) and addition (+) operators have the same precedence level and are evaluated from left to right (left associativity).
In the expression 5 - 2 + 1:
First, 5 - 2 is evaluated, resulting in 3.
Then, 3 + 1 is evaluated, resulting in 4.
Thus, the result of the expression 5 - 2 + 1 is 4.
Join the Discussion
Login to post a comment or share your explanation.
Login