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

**URL:** <https://discuss.codechef.com/t/what-is-the-difference-between-and-in-python/13320>\
**Category:** general\
**Tags:** python\
**Created:** [November 4, 2016, 8:34pm UTC](https://discuss.codechef.com/t/what-is-the-difference-between-and-in-python/13320 "2016-11-04T20:34:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sikderemran1](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@sikderemran1](https://discuss.codechef.com/u/sikderemran1)\
**Post date:** [November 4, 2016, 8:34pm UTC](https://discuss.codechef.com/t/what-is-the-difference-between-and-in-python/13320/1 "2016-11-04T20:34:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![suumo](https://discuss.codechef.com/user_avatar/discuss.codechef.com/suumo/32/3653_2.png) [@suumo](https://discuss.codechef.com/u/suumo)\
**Post date:** [November 4, 2016, 10:51pm UTC](https://discuss.codechef.com/t/what-is-the-difference-between-and-in-python/13320/2 "2016-11-04T22:51:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![raunak\_parijat](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@raunak\_parijat](https://discuss.codechef.com/u/raunak_parijat)\
**Post date:** [November 4, 2016, 11:10pm UTC](https://discuss.codechef.com/t/what-is-the-difference-between-and-in-python/13320/3 "2016-11-04T23:10:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sapfire](https://discuss.codechef.com/user_avatar/discuss.codechef.com/sapfire/32/3653_2.png) [@sapfire](https://discuss.codechef.com/u/sapfire)\
**Post date:** [November 5, 2016, 4:23am UTC](https://discuss.codechef.com/t/what-is-the-difference-between-and-in-python/13320/4 "2016-11-05T04:23:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![de\_day](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@de\_day](https://discuss.codechef.com/u/de_day)\
**Post date:** [January 8, 2017, 11:03am UTC](https://discuss.codechef.com/t/what-is-the-difference-between-and-in-python/13320/5 "2017-01-08T11:03:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vishal\_pimpalk](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@vishal\_pimpalk](https://discuss.codechef.com/u/vishal_pimpalk)\
**Post date:** [June 2, 2017, 3:45pm UTC](https://discuss.codechef.com/t/what-is-the-difference-between-and-in-python/13320/6 "2017-06-02T15:45:48Z")

</div>

= 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.

---

<div class="post-metadata">

**Author:** ![vijju123](https://discuss.codechef.com/user_avatar/discuss.codechef.com/vijju123/32/195207_2.png) [@vijju123](https://discuss.codechef.com/u/vijju123)\
**Post date:** [June 2, 2017, 4:08pm UTC](https://discuss.codechef.com/t/what-is-the-difference-between-and-in-python/13320/7 "2017-06-02T16:08:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hruday968](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@hruday968](https://discuss.codechef.com/u/hruday968)\
**Post date:** [June 2, 2017, 4:49pm UTC](https://discuss.codechef.com/t/what-is-the-difference-between-and-in-python/13320/8 "2017-06-02T16:49:27Z")

</div>

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