Question Detail

COS 102 If staments Objective Question

Question

Which of the following describes the difference between = and == in Python?
Options
A <code>=</code> is for comparison, <code>==</code> is for assignment.
B <code>=</code> is for assignment, <code>==</code> is for comparison.
Correct Answer
C Both <code>=</code> and <code>==</code> are used for assignment.
D Both <code>=</code> and <code>==</code> are used for comparison.
Correct Answer

Option B is the correct answer.

Detailed Explanation

Page 14, 'Mistake #1: = vs ==', clearly states: '= is for Assignment (giving a value)' and '== is for Comparison (checking a value)'.

Hint

This is a fundamental distinction in many programming languages. One sets a value, the other checks if values are the same.

Question Info