Exploring .append() and .extend() methods for 'list' datatype in Python.

<ListName>.append(x): If we want to update a list in python by populating elements after the last existing element then the .append(x) method is useful. Here, x is the element which is passed as an argument to the append method which will get appended to the list.This argument can be of any datatype, also an iterable, however the .append() will treat it as a single entity and thus append it at the end of the list.Example: l=[1,2,3,4];x={'a','b'}then, l.append(x) changes l to [1,2,3,4,{'a','b'}].

<ListName>.extend(x):If we want to update a list in python by populating it with elements from an iterable after the last existing element then the .extend(x) method is useful. Here, x is the iterable which is passed as an argument to the extend method, elements of which will get appended to the list.This argument x must be an iterable. The .extend() method will unpack the passed iterable and start appending each element in it to the list. Example: l=[1,2,3,4];x={'a','b'}then, l.extend(x) changes l to [1,2,3,4,'a','b'].