1Non_living_things = ["cars","chair","wire extender "]
2Non_living_things.extend(["Paper","Computer","Motherboard "])
3print(Non_living_things)
1#adding two or more elements in a list
2list1 = [1,2,3,4,5]
3list1.extend([6,7,8])
4print(list1)
5#output = [1, 2, 3 ,4 ,5, 6, 7, 8]
1fruits = ['apple', 'banana', 'cherry']
2cars = ['Ford', 'BMW', 'Volvo']
3
4fruits.extend(cars)
5
6print(fruits)
7# ['apple', 'banana', 'cherry', 'Ford', 'BMW', 'Volvo']
1# Difference between .append() and .extend() in python
2# .extend explained below :)
3
4list = ['hello', 'bro']
5my_list.append('append')
6
7print (my_list)
8>>> ['geeks', 'for', 'geeks']
9
10my_list.append ([6, 0, 4, 1])
11
12print (my_list)
13>>> ['geeks', 'for', 'geeks', [6, 0, 4, 1]]
14
15# For list.extend, each element of an iterable gets appended
16# to my_list
17
18my_list = ['geeks', 'for']
19another_list = [6, 0, 4, 1]
20my_list.extend(another_list)
21
22print (my_list)
23>>> ['geeks', 'for', 6, 0, 4, 1]
24
25# NOTE: A string is an iterable, so if you extend
26# a list with a string, you’ll append each character
27# as you iterate over the string.
28
29my_list = ['geeks', 'for', 6, 0, 4, 1]
30my_list.extend('geeks')
31
32print (my_list)
33>>>['geeks', 'for', 6, 0, 4, 1, 'g', 'e', 'e', 'k', 's']
34
35# and yup I have copied it.
36# Originally by Yvant2000
1techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga techlux.ga
1The extend() method adds the specified list elements (or any iterable) to the end of the current list.