List

Lists are Python’s most flexible ordered collection object type. It can also be referred to as a sequence that is an ordered collection of objects that can host objects of any data type, such as Python Numbers, Python Strings and nested lists as well. Lists are one of the most used and versatile Python Data Types. In this module, we will learn all about lists in order to get started with them.

Creating a Lists in python

A list can be created by putting the value inside the square bracket, and values are separated by commas.
List_name = [value1, value2, …, value n]
Unlike strings, lists can contain any sort of objects: numbers, strings, and even other lists. Python lists are:

Example:

list1 = [1,2,3,4,5]
list2 = [“hello”, “intellipaat”]

Creating Multi-dimensional Lists in Python

A list can hold other lists as well which can result in multi-dimensional lists. Next, we will see how to create multi-dimensional lists, one by one.
One-dimensional Lists in Python:

init_list = [0]*3
print(init_list)
Output:
[0, 0, 0]

Two-dimensional Lists In Python:

two_dim_list = [ [0]*3 ] *3
print(two_dim_list)
Output: 
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]

Three-dimensional Lists in Python:

two_dim_list = [[ [0]*3 ] *3]*3
print(two_dim_list)
Output: 
[[[0, 0, 0], [0, 0, 0], [0, 0, 0]],
[[0, 0, 0], [0, 0, 0], [0, 0, 0]],
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]]