Python List extend() Method
The Python’s List extend() method iterates over an iterable like string, list, tuple, etc., and adds each element of the iterable to the end of the List, modifying the original list.
Python List extend() Syntax:
Syntax: list.extend(iterable)
Parameters:
- iterable: Any iterable (list, set, tuple, etc.)
Returns: None
Python List extend() Example:
Python3
l = [1, 2, 3]l.extend([4, 5, 6])print(l) |
Output:
[1, 2, 3, 4, 5, 6]
Example 1: Add Elements of Tuple and Set to List
Using list extend() method to add elements from Tuple or Set to List.
Python
# My Listmy_list = ['geeks', 'for', 'geeks']# My Tuplemy_tuple = ('DSA', 'Java')# My Setmy_set = {'Flutter', 'Android'}# Append tuple to the listmy_list.extend(my_tuple)print(my_list)# Append set to the listmy_list.extend(my_set)print(my_list) |
Output:
['geeks', 'for', 'geeks', 'DSA', 'Java'] ['geeks', 'for', 'geeks', 'DSA', 'Java', 'Android', 'Flutter']
Example 2: Extend String to the List
A string is iterable, so if you extend a list with a string, you’ll append each character as you iterate over the string.
Python3
# My listmy_list = ['geeks', 'for', 6, 0, 4, 1]# My stringmy_list.extend('geeks')print(my_list) |
Output:
['geeks', 'for', 6, 0, 4, 1, 'g', 'e', 'e', 'k', 's']


