Python List With Examples

Today we going to learn about Python List. Earlier we learnt about Python Numbers which can be found here.

Python List

List is a versatile datatype available in Python. Basically a python list is comma-separated values which are called items. List in python is written within square brackets. Interestingly it’s not necessary for items in a list to be of same types. For example;

The above code will produce the following output.

list Example Declare


Accessing Items in Python List

Each item of a list is assigned a number – it’s position or index. The first index is zero, the second index is one, and so forth.

To access items in a list, we can use these index number within a square bracket. For example;

The above code will produce output like below.



Surprising fact is index can be negative. It means to read not from the left rather from the right of the list.

The output of the above code will be like below-



Update A List Item

We can update one or more item of a list simply through the index of that item.

The output will be like below.

list Example Declare


Deleting an item in a list

To delete an item in a list, there are several methods. Look at the following example to explore it further.

The above code will produce output like below.



Some built-in python list functions

There are some built-in functions to manipulate list in python. Let’s look at the following example for understanding.

The output of the above code will be as follows.

Python List


So this is all about python lists for now. Make sure to run every piece of code on you own. Feel free to leave a comment if you have any doubt.
#happy_coding 🙂


By admin

Leave a Reply