
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How do I create a multidimensional list in Python?
Multidimensional Lists are Lists within Lists. The left index as row number and right index as column number, for example
list[r][c]
Above, r is row number and c is column number.
Let’s see an example. For multidimensional list 2x3 −
list [2][3]
Create a Multidimensional Python List
Example
In this example, we will learn how to create a Multidimensional List in Python. We will also iterate and print the array.
# Create a Multi-Dimensional Python List mylist = [[2,5], [10,24,68], [80]] print("\nMultidimensional List") for outList in mylist: print(outList)
Output
Multidimensional List [2, 5] [10, 24, 68] [80]
How to access elements in a Multidimensional Python List
Example
In this example, we will learn how to access elements in a multidimensional list. Access using square brackets −
# Create a Multi-Dimensional Python List mylist = [[2,5], [10,24,68], [80]] print("\nMultidimensional List") for outList in mylist: print(outList) # Accessing Third element in the 2nd row print("\nThird element in the 2nd row = \n",mylist[1][2])
Output
Multidimensional List [2, 5][10, 24, 68] [80] Third element in the 2nd row = 68
Append elements in a Multidimensional List
Example
The append() method is used to append elements in a Multidimensional List. The elements added will get appended i.e. in the end −
# Create a Multi-Dimensional Python List mylist = [[2,5], [10,24,68], [80]] print("Multidimensional List") for outList in mylist: print(outList) # Append elements mylist.append([65, 24]) print("\nDisplaying the updated Multidimensional List") for outList in mylist: print(outList)
Output
Multidimensional List [2, 5] [10, 24, 68] [80] Displaying the updated Multidimensional List [2, 5] [10, 24, 68] [80] [65, 24]
- Related Articles
- How do I create a constant in Python?
- How do I create a Python namespace?
- How do I create a .pyc file in Python?
- How do I create a namespace package in Python?
- How do I create a user interface through Python?
- How do we create python string from list?
- How do I list all files of a directory in Python?
- How do I get list of methods in a Python class?
- How do you create a list in Java?
- How do I create documentation from doc strings in Python?
- How to create a multidimensional JavaScript object?
- How do I empty a list in Java?
- How do I search a list in Java?
- How do I create child windows with Python tkinter?
- How do I create a view in MySQL?

Advertisements