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

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

= is used for assignation of value and
== is used for comparison of two variable,list or string

The = is a simple assignment operator. It assigns values from right side operands to the left side operand.

While on the other hand == checks if the values of two operands are equal or not. If yes, the condition becomes true and it returns a non zero value.

For example,

a=10 #The value 10 will be stored in the integer variable a.

if(a==10): #This will check if the value stored in variable a is equal to 10. If yes it will return a non zero value.

1 Like

In pretty much all programming languages, the single ‘=’ and double ‘==’ have different purposes, and that often trips up beginners. In languages like C, Python, Java, JavaScript, and many others:

= is the assignment operator. In other words, it sets a particular variable equal to a particular value (or another variable). For instance, the following code demonstrates this operator: c = 5. Let’s say we’ve declared the c variable before, and now we’re assigning it the value of 5.

== is the equality operator. It is used in true/false expressions to check whether one value is equal to another one. For example, (2 + 2) == 5 evaluates to false, since 2 + 2 = 4, and 4 is not equal to 5. The equality operator doens’t set any value, it only checks whether two values are equal.

define = :
the = symbol is used t make variable and is used to say something is something else from now on

define == :
the == symbol means that if something happens, then a certain condition will happen

= is assignment of right side operand to the left hand operand.
== is used for checking value of an operand. It is generally used for some decision making and accordingly defining action.

I am curious why you decided to bump such an old question.

i think he want karma but this is the only question in the forum which he can answer

1 Like
//