Test Index
CBSE Class 12 Computer Science 2025 Paper Compartment
© examsnet.com
Question : 22 of 37
Marks:
+1,
-0
What is the difference between
= and == in Python ? Give an example of each.
Solution:
Difference:
Examples:
| = (assignment operator) | == (relational / comparison operator) |
|---|---|
| Assigns (stores) the value on its right to the variable on its left. | Compares the values on its two sides and checks whether they are equal. |
| It does not produce a value; it is used in a statement. | It gives a Boolean result: True or False. |
a = 5 # = assigns the value 5 to aprint(a == 5) # == compares: True, since a holds 5print(a == 7) # FalseKey point: Writing
if a = 5: is a SyntaxError; a condition needs ==.© examsnet.com
Go to Question: