Python List Merging with extend() Method

🚀 Python Practice – Using extend() to Merge Lists! Today I explored another way to combine lists in Python using the extend() method 🐍 🔹 Sample Code: alist = ['praveen','ajay','san','kiran','chandru','fun','joy','rrrr'] blist = ['run','jun','jam'] alist.extend(blist) print(alist) ✅ Key Learnings: 🔸 extend() adds elements of one list to another 🔸 It modifies the original list (no new list is created) 🔸 Faster and more memory-efficient compared to creating a new list 💡 Output: ['praveen', 'ajay', 'san', 'kiran', 'chandru', 'fun', 'joy', 'rrrr', 'run', 'jun', 'jam'] 📌 Difference from + operator: + → creates a new list extend() → updates existing list ⚡ Useful in real-world scenarios like: Merging logs Combining datasets Automation scripts in DevOps #Python #DevOps #Learning #Automation #CodingJourney #Programming #Beginners

To view or add a comment, sign in

Explore content categories