List append is used to append element in the list in python. for an instance a is list as shown below write a. press tab after typing dot(.)
Example of Python List.Append():
a=[‘apple’,’orange’,’mango’]
To append element in List
a.append(“guavava”)
and element will be added in list.
when we try to append 2 items in list it will throw error
Error:list.append() takes exactly one argument (2 given)
To solve this we have to make list of element which we want to add then we can either use List.extend function in python or it can be done by just simple adding two list.for example.
If a and b are two list.
a=[‘a’,’b’]
b=[‘v’,’c’]
now we have to append element of b to a. for this we just simple write a+b as shown in image below.
Element of list b will be appended to list a.
[…] 1.List.append: To append element in list. […]
[…] is always confusion between list.append & list.extend.Lets see an example where a and b are two list as shown […]