Test Index

Python Revision Tour Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 50 of 102
Marks: +1, -0
What is the difference between = and == in Python ? Give an example of each.
[CBSE 2025 Compartment]
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: