What is the primary difference between the methods append() and extend() when applied to a list?

  • append() adds one item
  • append() extends lists
  • extend() adds elements
  • extend() appends lists
The primary difference between append() and extend() is that append() adds a single item to the end of a list, while extend() adds the elements of an iterable (e.g., another list) to the end of the list. This means extend() is used to combine two lists, while append() adds an element as it is, even if it's a list itself.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *