What is the difference between using list_a + list_b and list_a.extend(list_b) in Python?
💡 Model Answer
Using list_a + list_b creates a new list that contains the elements of both lists, leaving list_a and list_b unchanged. The operation returns a new list object and has a time complexity of O(n+m). In contrast, list_a.extend(list_b) mutates list_a in place by appending each element of list_b to it; it returns None and has a time complexity of O(m). Use + when you want to preserve the original lists or need an immutable result; use extend when you want to modify the first list directly and avoid allocating a new list.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500