What is the difference between = and == operators in Python?


In Python = symbol is defined as assignment operator. It requires one variable on its left and an expression on its right. Value of the expression on right is assigned to variable on left. Expression and name of variable are not interchangeable.

>>> a=10
>>> b=20
>>> c=a+b
>>> a,b,c
(10, 20, 30)
>>> a+b=c
SyntaxError: can't assign to operator

The == symbol is a comparison operator and called equal to operator. It returns true if operands on either side are equal, otherwise it returns false

>>> 10+2 == 10
False
>>> (10+2) == 12
True
>>> 'computer' == 'Computer'
False
>>> 'computer' == "computer"
True

Updated on: 26-Feb-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements