Lists: Python

MOHIT MEHLAWAT
3 min readJul 13, 2021

A List in Python is used to store the sequence of various datatypes. They are ordered and have a definite count. Lists in Python are mutable, which means, that the elements of the list can be modified after its creation. The elements in a list are indexed according to a definite sequence and the indexing of a list is done with 0 being the first index.

Indexing and Slicing

The items of the list are indexed with 0 being the first index. The index operator [] is used to access an item in a list. The index must be an integer.

Concatenate a List

The operator + is used to concatenate a list.

List Methods

Lists in Python tend to be more flexible than arrays in other languages because they has no fixed size and no fixed type constraints. Some of the most commonly used methods of list are shown below.

There are many more methods which can be found at this link.

Nesting Lists

A great feature of Python data structure is that it supports nesting, that is, a data structure within a data structure. The example shows the list within a list.

List Comprehensions

Python supports an advanced feature which allows for quick construction of lists called as list comprehension. For creating a list comprehension for loops are used.

--

--