Computer Science, asked by dgill3105, 8 months ago

Explain list.extend(seq)

Answers

Answered by staeen
0

Answer:

Python list extend() is an inbuilt function that adds the specified list elements (or any iterable) to the end of the current list. The extend() extends the list by adding all items of the list (passed as an argument) to an end.

Answered by letmeanswer12
0

Python list method extend() appends the contents of seq to list.

Explanation:

Python list method extend() iterates over its argument and adding each element to the list and extending the list. The length of the list added by the number of items in its argument.

  • Syntax - list.extend(seq)
  • Parameters - (seq) − This represents the list of elements
  • Return Value - This method will not return any value but adds to the existing list of the content.

Example:

  • List1 = [1, 2, 3]  
  • List2 = [2, 3, 4, 5]  
  • # Add List2 to List1  
  • List1.extend(List2)          
  • print(List1)  

Output:

  • [1, 2, 3, 2, 3, 4, 5]

Similar questions