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

PythonServer Side ProgrammingProgramming

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
Published on 13-Feb-2018 14:23:46