add list to a list code example
Example 1: python append vs extend
my_list = [23, 11, 42, 24523]
my_list.append([34523, 76979])
print(my_list)
my_list.extend([12, 99])
print(my_list)
"""
Output:
[23, 11, 42, 24523, [34523, 76979]]
[23, 11, 42, 24523, [34523, 76979], 12, 99]
"""
Example 2: add list python
my_list = ['a', 'b', 'c']
my_list.append('e')
print(my_list)
Example 3: how do i add to a list in python
a=[1,2,3,4]
a+=[5,6]
Example 4: add to a list python
lst = [1, 2, 3]
li = 4
lst.append(li)
.append("the add"): append the object to the end of the list.
.insert("the add"): inserts the object before the given index.
.extend("the add"): extends the list by appending elements from the iterable.