In python a += b doesn’t always behave the same way as a = a + b, same operands may give the different results under different conditions.
Consider these examples for list manipulation:
[5, 4, 3, 2, 1, 1, 2, 3, 4] [5, 4, 3, 2, 1, 1, 2, 3, 4]
[5, 4, 3, 2, 1, 1, 2, 3, 4] [5, 4, 3, 2, 1]
- expression list1 += [1, 2, 3, 4] modifies the list in-place, means it extends the list such that “list1” and “list2” still have the reference to the same list.
- expression list1 = list1 + [1, 2, 3, 4] creates a new list and changes “list1” reference to that new list and “list2” still refer to the old list.
- Python - Read blob object in python using wand library
- Python | Convert list to Python array
- Python | Index of Non-Zero elements in Python list
- Important differences between Python 2.x and Python 3.x with examples
- Reading Python File-Like Objects from C | Python
- Python | Merge Python key values to list
- Python | PRAW - Python Reddit API Wrapper
- MySQL-Connector-Python module in Python
- twitter-text-python (ttp) module - Python
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- Python | Add Logging to Python Libraries
- Python | Add Logging to a Python Script
- Python | Visualizing O(n) using Python
- abs() in Python
- bin() in Python
- Use of min() and max() in Python
- max() and min() in Python
- pow() in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : aayushibhatia2