Professional Documents
Culture Documents
List is a sequence of values of any type. Values in the list are called elements / items. List is enclosed
in square brackets.
Example: a = [1,2.3,"Hello"]
List is one of the most frequently used and very versatile data type used in Python.
Example:
#empty list
empty_list = []
#list of integers
age = [15,12,18]
A list can also have another list as an item. This is called a nested list.
# nested list
1) List Index
2) Negative Indexing
List Index:-
A list index is the position at which any element is present in the list. Index in the list starts from 0,
so if a list has 5 elements the index will start from 0 and go on till 4. In order to access an element in
a list we need to use index operator [].
Negative Indexing: -
Python allows negative indexing for its sequences. The index of -1 refers to the last item, -2 to the
second last item and so on.
Adding Element to a List :- Elements from a list can removed using two
methods: -
We can add an element to any list using two
methods : 1) Using remove() method