Difference between append and extend in list in python

Spread the love

Before going further, we need to run one example on this, we can get to know understand.

a = [1, 2] a.append([3, 6]) print("By using append method", a) a = [1, 2] a.extend([3, 6]) print("By using extend method", a)

By observing the above example, you will get know understand

Extend():  This extend will simply adding the elements to that old list

Append(): This method  it append a object at end of the list

Extend Reference

Append Reference



Leave a Reply

Your email address will not be published. Required fields are marked *