Test Index

CBSE Class 12 Computer Science 2025 Paper Compartment Get it on Google PlayDownload on the App Store

© examsnet.com
Question : 22 of 37
Marks: +1, -0
What is the difference between = and == in Python ? Give an example of each.
Solution:  
Difference:
= (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.
Examples:
a = 5          # = assigns the value 5 to a
print(a == 5) # == compares: True, since a holds 5
print(a == 7) # False
Key point: Writing if a = 5: is a SyntaxError; a condition needs ==.
© examsnet.com
Advertisements
Go to Question: