How Can We Help?
Introduction:
In this tutorial, we are going to explain how to use Python list extend() Method with basic syntax and many examples for better understanding.
Python list extend() method It appends the contents of passed sequence to the given list and returns updated given list
Syntax:
<list_variable_name>.extend(seq)
Input Parameters:
- seq : is a list of elements which to be append to list .
- list_variable_name : The lists that we want to count a particular element inside.
Example
num1=[1,2,3] num2=[4,5,6] num1.extend(num2) print("Extended list: ", num1)
Output of example
Extended list: [1, 2, 3, 4, 5, 6]
In the above example, we can easily insert the values of list variable num2 in num1 by using command as ” num1.extend(num2)”. The output returns updated list ‘num1’.
In this tutorial, you have learned how to append a list to another list using Python list extend() method.
Hopefully, it was clear and concise.
If you have a inquiry or doubt don’t hesitate to leave them in comment. we are waiting your feedback as well.
Similar Python list Methods:
- list.append(object) : It appends object to the given list.
- list.count(object) : It returns count of how many times object occurs in the list.
- list.index(object) : It returns the lower index value of passed object in the list, if object is present in the list.
- list.insert(index,object) : It inserts object into the list at offset index.
- list.pop(obj=list[-1]) : It removes last object from the list and returns removed object of a list.
- list.remove(object) : It removes object from the list.
- list.reverse() : It reverses objects of list in place.
- list.sort([func]) : It sorts objects of a list and use compare func, if given.
Python tutorials list:
- Python tutorials list : access all python tutorials.