Examveda

What is the result of 5 - 2 + 1 ?

A. 2

B. 4

C. -2

D. 3

Answer: Option B

Solution (By Examveda Team)

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.

This Question Belongs to Python Program >> Precedence And Associativity

Join The Discussion

Comments (1)

  1. Shubham Khedekar
    Shubham Khedekar:
    1 year ago

    option B of these question. please recheck of that question

Related Questions on Precedence and Associativity