Saturday, October 27, 2018

List in python

In order to store a set of variable, we use a list.

A list can be illustrated as a box queue in a line, and we add our value to each box.

The box can be accessed using the box position. We would call it index.

In python index should start from 0.

So, first element is in index 0, second element is in index 1.. and so on.

We add an element to a list by .append(new value). myList.append("newValue")

We will be able to access an element by []

Let us have a list name myList, to get the first element, we will use myList[], second element, myList[1] and so on.

To remove an element from a list, use .pop(index).
To remove the first element, I use myList.pop(0)
To get the first element of a list and remove it, I use removelement = myList.pop(0)

Please do refer to the example below for better understanding on how to add element to a list , access the element of list. remove an element from a list.

There is another question regarding list.
Encyclopedia question


No comments:

Post a Comment

Superior of partial fraction

What is complex fraction? Complex fraction is a fraction whereby its numerator or denominator or both consists of fractions. Partial frac...