TechSavvy
TechSavvy 6d ago • 20 views

Python List Extend Example: Adding Multiple Elements

Hey everyone! 👋 Let's dive into how to extend Python lists! We'll cover the basics and then test your knowledge with a quick quiz. Ready? Let's go! 💻
💻 Computer Science & Technology
🪄

🚀 Can't Find Your Exact Topic?

Let our AI Worksheet Generator create custom study notes, online quizzes, and printable PDFs in seconds. 100% Free!

✨ Generate Custom Content

1 Answers

✅ Best Answer
User Avatar
chavez.allen15 Dec 30, 2025

📚 Quick Study Guide

  • 🔍 The `extend()` method in Python is used to add multiple elements to the end of a list.
  • 🐍 Unlike `append()`, which adds a single element (which could be another list) to the end, `extend()` unpacks an iterable (like another list, tuple, or string) and adds each element individually.
  • 📝 Syntax: `list1.extend(iterable)` where `list1` is the list to be extended and `iterable` provides the elements to add.
  • 💡 Example: If `list1 = [1, 2, 3]` and you use `list1.extend([4, 5, 6])`, `list1` will become `[1, 2, 3, 4, 5, 6]`.
  • 🧮 You can extend a list with tuples: `list1.extend((7, 8))` will add 7 and 8 to the list.
  • 🧪 You can extend a list with strings: `list1.extend("abc")` will add 'a', 'b', and 'c' individually to the list.
  • ⚠️ Be careful! If you try to extend with a non-iterable (like an integer), Python will raise a `TypeError`.

Practice Quiz

  1. Which of the following methods is used to add multiple elements from an iterable to the end of a list in Python?
    1. append()
    2. extend()
    3. insert()
    4. add()
  2. What will be the output of the following code? python list1 = [1, 2, 3] list1.extend([4, 5]) print(list1)
    1. [1, 2, 3, [4, 5]]
    2. [1, 2, 3, 4, 5]
    3. [1, 2, 3, (4, 5)]
    4. Error
  3. Which data type can be used as an argument to the `extend()` method?
    1. Integer
    2. String
    3. Boolean
    4. None of the above
  4. What happens if you try to extend a list with a non-iterable, such as an integer?
    1. The integer is added as a single element to the list.
    2. The list remains unchanged.
    3. A TypeError is raised.
    4. The integer is converted to a string and added.
  5. What will be the output of the following code? python list1 = [1, 2] list1.extend((3, 4)) print(list1)
    1. [1, 2, (3, 4)]
    2. [1, 2, 3, 4]
    3. Error
    4. [1, 2, [3, 4]]
  6. Which of the following is the correct way to extend a list called `my_list` with the elements 'x', 'y', and 'z'?
    1. my_list.extend('x', 'y', 'z')
    2. my_list.extend(['x', 'y', 'z'])
    3. my_list.extend('xyz')
    4. Both B and C
  7. What will `list1` contain after the following operations? python list1 = [10, 20] list1.extend("30") list1.extend([40])
    1. [10, 20, "30", [40]]
    2. [10, 20, 30, 40]
    3. [10, 20, '3', '0', 40]
    4. Error
Click to see Answers
  1. B
  2. B
  3. B
  4. C
  5. B
  6. D
  7. C

Join the discussion

Please log in to post your answer.

Log In

Earn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! 🚀