Lists in Python

The lists in python are containers to store a set of values of any data type.

Example –

lists in python

The lists in python can contain different types of elements such as integer, float, string, Boolean, etc.

Above list is a collection of different types of elements which we can use in lists.

Indexing of lists

Indexing of lists is incredibly easy to understand. If a programmer wants to work on the first element of the list then it will count as a zero(0) index. Lets understand this by taking an example.

indexing of lists

(This is known as List Slicing)

list slicing in python

List Methods:

1. sort( ) = updates the list in our desirable elements. Like –

sort method

2. reverse() = updates the list in a reverse mode.

reserve method

3. append() = add programmer’s particular element at the end of the list.

append method

4. insert( ) =This will add programmer’s particular choice of element at the index which is chosen by him/her. Like –

insert method

5. pop(3) = It will delete an element at index 3 and return its value. Like –

pop method

6. remove(5) = It will remove 5 from the list.

remove method

Leave a Reply

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