DEV Community

Onaolapo-11
Onaolapo-11

Posted on

Extend vs Append. I looked at the basic difference.

Extend adds multiple elements to the list, while append adds just one element to the list.

I was unable to study on October 27th.

Day 68 [October 28, 2025]

I need to buckle down, as I'm still lagging on day day 3 & 4 goals, "Day 3-4: Control structures (if-else, loops)", as well as day 5 (and 6) goals, "Day 5-6: Functions and modules", and Day 7 target (exercises) (Meta AI, personal communication, August 8, 2025). If I haven't covered this, I can't make progress on day 8 - 67 goals.

Goals:
As extracted from the 'Python for Software Development' textbook by Halvorsen (n.d.):

  • Plotting in Python ✅
  • Subplots✅
  • Exercises✅
  • If ... Else
  • Arrays
  • For Loops
  • Nested
  • For Loops
  • While Loops
  • Exercises
  • Creating Functions in Python - Introduction
  • Functions with multiple return values
  • Exercises
  • Creating Classes in Python
  • The init () Function
  • Exercises
  • Creating Python Modules
  • Exercises

Notes:
Python for Data Science, AI & Development Course (IBM) (Santarcangelo, n.d.):
Module 2: Python Data Structures

  • Lists and Tuples
  • Dictionaries
  • Sets

Lists
Extend vs Append

  • Extend adds multiple elements to the list, while append adds just one element to the list, as explained below

Extend:
shopping_list = ["Watch", "Laptop","Shoes","Pen", "Clothes"] #list excerpted basically from Santarcangelo (n.d.)
shopping_list.extend(["Football", "Phone"])
shopping_list
Outputs:
['Watch', 'Laptop', 'Shoes', 'Pen', 'Clothes', 'Football', 'Phone']

shopping_list = ["Watch", "Laptop","Shoes","Pen", "Clothes"] #list excerpted basically from Santarcangelo (n.d.)
shopping_list.extend("Football") #notice no list within the parenthesis
shopping_list
Outputs:
['Watch', 'Laptop', 'Shoes', 'Pen', 'Clothes', 'F', 'o', 'o', 't', 'b', 'a', 'l', 'l']

Append:
shopping_list = ["Watch", "Laptop","Shoes","Pen", "Clothes"] #list excerpted basically from Santarcangelo (n.d.)
shopping_list.append(["Football", "Phone"])
shopping_list
Outputs:
['Watch', 'Laptop', 'Shoes', 'Pen', 'Clothes', ['Football', 'Phone']] #append adds just one element to the list

shopping_list = ["Watch", "Laptop","Shoes","Pen", "Clothes"] #list excerpted basically from Santarcangelo (n.d.)
shopping_list.append("Football") #notice no list within the parenthesis
shopping_list
Outputs:
['Watch', 'Laptop', 'Shoes', 'Pen', 'Clothes', 'Football'] #append adds just one element to the list

Summary:
Extend vs Append. I looked at the basic difference. Extend adds multiple elements to the list, while append adds just one element to the list.

References:

  1. Halvorsen, H. (n.d.). Python. https://halvorsen.blog/documents/programming/python/python.php#python4

  2. Santarcangelo, J. (n.d.). Python for data science, AI & development [MOOC]. Coursera. https://coursera.org/learn/python-for-applied-data-science-ai

Top comments (0)