whats the difference between insert and append ? with python code.

"insert" and "append" method in list in Python

bigginer basically get confused when to use insert and append method in list.

heras is the very simple understanding format of  it. 

 insert:

to add some element in the list at certain position.

append:

to add element in the list.

code:

append

...................................................................................................................

shop=['bread','banana','egg']

shop.append("apple")

print(shop)

output:

['bread', 'banana', 'egg', 'apple']
.....................................................................
insert:
python code:
shop.insert(2,"lemmon")
shop
output:
['bread', 'banana', 'lemmon', 'egg', 'apple']


 

Comments

Popular posts from this blog

spealized the work. Be ready for the future

lest just create a basic bot operation in python

scatterplot/ violon plot /histogram /boxplot