There are a number of collection types in Python. While types such as int and str hold a single value, collection types hold multiple values.

Lists

The list type is probably the most commonly used collection type in Python. Despite its name, a list is more like an array in other languages, mostly JavaScript. In Python, a list is merely an ordered collection of valid Python values. A list can be created by enclosing values, separated by commas, in square brackets:

int_list = [1, 2, 3]
string_list = ['abc', 'defghi']

A list can be empty:

empty_list = []

The elements of a list are not restricted to a single data type, which makes sense given that Python is a dynamic language:

mixed_list = [1, 'abc', True, 2.34, None]

A list can contain another list as its element:

nested_list = [['a', 'b', 'c'], [1, 2, 3]]

The elements of a list can be accessed via an index, or numeric representation of their position. Lists in Python are zero-indexed meaning that the first element in the list is at index 0, the second element is at index 1 and so on:

names = ['Alice', 'Bob', 'Craig', 'Diana', 'Eric']
print(names[0]) # Alice
print(names[2]) # Craig

Indices can also be negative which means counting from the end of the list (-1 being the index of the last element). So, using the list from the above example:

print(names[-1]) # Eric
print(names[-4]) # Bob

Lists are mutable, so you can change the values in a list:

names[0] = 'Ann'
print(names)
# Outputs ['Ann', 'Bob', 'Craig', 'Diana', 'Eric']

Besides, it is possible to add and/or remove elements from a list:

Append object to end of list with L.append(object), returns None.

names = ['Alice', 'Bob', 'Craig', 'Diana', 'Eric']
names.append("Sia")
print(names) 
# Outputs ['Alice', 'Bob', 'Craig', 'Diana', 'Eric', 'Sia']

Add a new element to list at a specific index. L.insert(index, object)