“List And Methods In a List”

Sandeshgaikwad
4 min readOct 1, 2023

--

Hello friends, Sandesh here again.
In last article we have seen introduction about list,

https://medium.com/@sandeshgaikwad14/what-is-list-in-python-c545909c495b

in this article we will see how to create a list and what are the different methods in a list.
As we learned list is heterogeneous, ordered and indexed. We can modified list due to its mutable properties. Let have some examples for how we concatenate the list.
lets create list first and then starts concatenation.
list1=[1,2,3,4] and list2=[5,6,7,8]
We used + operator to merge two list.

We can create new list by merging old two lists by using + operator.

We can assigned list value or the items to the existing list.

We can repeat the the list by using * operator.

Indexing and slicing in a list.

We have seen indexing and slicing in string type, the same logic we need to put here by analysing the nested list.

Indexing
By doing indexing we can extract any element from the list or the nested list.

By doing slicing we can extract multiple elements or the elements from the list and nested list.

Now we will see the methods in a list.
To see what are the methods present for the list, we can simply run
print(dir(list))

Append method
By this method we can add element or item or the nested list to the existing list. It will add that item at the last of the list.

Clear method.

By using this method we can clear all the items from the list.

Count method

By using thi smehod we can count the occurrences of an element.

Extend method.
By using this method we can add some items or the list at the end of the list.

Index method
By using this method we can find the index of the item.

Insert method.
By using this method we can add item at whatever place with help of index.

Pop method
By using this method we can pop out any item from the list.

Remove method
By this method we can remove any item from the list.

Reverse method
We can rearrange the list by ascending order or descending order

Sort method
By using this method we can sort the items from the list and arrange it.

So Friends this is all about the list. We will meet in next article with tuple.
I hope this article is helpful for you all.
Thanks.

#vevcode
@sandeshgaikwad.

--

--