Difference Between x = x + y and x += y in Python Last Updated : 10 May, 2020 Comments Improve Suggest changes Like Article Like Report We often use x += y instead of x = x + y. So, are they same or different? Let's Find it here. Example 1: Python3 x = [1, 2] another_x = x y = [3] x += y print(x) print(another_x) Output: [1, 2, 3] [1, 2, 3] Example 2: Python3 x = [1, 2] another_x = x y = [3] x = x + y print(x) print(another_x) Output: [1, 2, 3] [1, 2] So here we find that both codes are almost similar but still there are difference in the outputs. So the reason behind this is that for many types of objects, x += y will modify the object referred to by x in-place, whereas x = x + y will create a new object and reassign x to it. This distinction is important if you still have another reference to the object somewhere like in this case another_a is another reference to the object. However, many objects such as numbers and strings are "immutable" - they can't be modified in-place - and for those objects, x += y and x = x + y will typically do exactly the same thing. But if you write your own class you can customize what + and += do when used with objects of that class, and you can make them do completely different things if you really want to. Example 3: Python3 x = "12345" another_x = x y = "67890" x += y print(x) print(another_x) Output: 1234567890 12345 Example 4: Python3 x = "12345" another_x = x y = "67890" x = x + y print(x) print(another_x) Output: 1234567890 12345 Comment More infoAdvertise with us Next Article Difference Between x = x + y and x += y in Python K kapadiamiraj1133 Follow Improve Article Tags : Python python-basics Practice Tags : python Similar Reads Difference between + and , Python Print In this article, we will learn about the difference between + and, in Python print, The print() function in Python is used to print some messages as the output on the screen. We can print a single element or even multiple elements on the screen. Python provides two ways to print multiple elements as 3 min read Python - Difference between := and == In this article, we will be discussing the major differences between Walrus(:=) and the Comparison operator (==):= in PythonThe := operator in Python, also known as the walrus operator or assignment expression, was introduced in Python 3.8. It enables assignment and evaluation to happen simultaneous 2 min read Difference Between '+' and 'append' in Python + Operator creates a new sequence by concatenating two existing sequences and .append() method (available for lists) modifies the existing list in place by adding one item at the end. In this article we are going to compare '+' operator and append in Python.+ Operator in Python+ operator is typicall 3 min read Difference between 'and' and '&' in Python and is a Logical AND that returns True if both the operands are true whereas '&' is a bitwise operator in Python that acts on bits and performs bit-by-bit operations.Note: When an integer value is 0, it is considered as False otherwise True when used logically.and in PythonThe 'and' keyword in P 6 min read Difference between return and print in Python In Python, we may use the print statements to display the final output of a code on the console, whereas the return statement returns a final value of a function execution which may be used further in the code. In this article, we will learn about Python return and print statements. Return Statement 2 min read Like