What will be the output of print(3 + 4 * 2) in Python?
Correct answer
B. 11
8 views
B. 11
8 views
Multiplication is carried out before addition because it has higher precedence, so the expression is evaluated as 3 + 8, giving 11. Anyone who simply works from left to right gets 14, which is the classic mistake here. Brackets, as in (3 + 4) * 2, would be needed to obtain 14.
Asked in: Matric,FBISE
Not sure why the answer is B? Ask here and get an explanation.