---
description: Array is a data structure used to store elements. An array can only store similar types of elements. A Two Dimensional is defined as an Array inside the Array. The index of the array starts with 0 and ends with a size of array minus 1.
title: "Python 2D Arrays: Two-Dimensional List Examples"
image: https://www.guru99.com/images/python-2d-arrays.png
---

[Skip to content](#main)

**⚡ Smart Summary**

Python 2D Array is an array placed inside another array, forming rows and columns like a table. The examples below show how to create, access, insert, update, delete, and size 2D arrays.

- 🧱 **Structure:** A 2D array is an array of arrays in rows and columns.
- 🔢 **Indexing:** Access an element with array\[row]\[column]; indexes start at 0.
- ➕ **Insert and Update:** Add rows with insert() and change values by index.
- 🗑️ **Delete and Size:** Remove rows with del and count rows with len().
- 🔁 **Iteration:** Use nested for loops to traverse rows and columns.
- 🧮 **NumPy Option:** For heavy numeric work, create true 2D arrays with numpy.array() for speed.

Read More

![Python 2D Array]()

## What is a Two Dimensional Array in Python?

Array is a data structure used to store elements. An array can only store similar types of elements. A Two Dimensional is defined as an Array inside the Array. The index of the array starts with 0 and ends with a size of array minus 1. We can create ‘n’ number of arrays in an array.

[![Python 2D Arrays]()](https://www.guru99.com/images/python-2d-array-2.webp)

In the above image, we can see that an index uniquely identifies each array element.

## How to Create Array in Python?

We can create a two-dimensional array(list) with rows and columns.

**Syntax**:

```
[[r1,r2,r3,..,rn],[c1,c2,c3,.......,cn]]

```

**Where,**

r stands for rows and c stands for columns

**Example:** Following is the example for creating

2D array with 4 rows and 5 columns

```
array=[[23,45,43,23,45],[45,67,54,32,45],[89,90,87,65,44],[23,45,67,32,10]]
#display
print(array)

```

**Output:**

```
[[23, 45, 43, 23, 45], [45, 67, 54, 32, 45], [89, 90, 87, 65, 44], [23, 45, 67, 32, 10]]

```

## Accessing the values

We can access the values using index position

**Syntax**:

We can get row value using `[]` operator

```
array[row index]
```

We can get column value using `[][]`

```
Array[row index][column index]
```

where,

- array is an input array
- row index is the row index position starts from 0
- column index is the column index position starts from 0 in a row.

**Example:**

In this example we are going to access the values using index positions

```
#creare 2D array with 4 rows and 5 columns
array=[[23,45,43,23,45],[45,67,54,32,45],[89,90,87,65,44],[23,45,67,32,10]]

#display
print(array)

#get the first row
print(array[0])

#get the third row
print(array[2])

#get the first row third element
print(array[0][2])

#get the third row forth element
print(array[2][3])

```

**Output:**

```
[[23, 45, 43, 23, 45], [45, 67, 54, 32, 45], [89, 90, 87, 65, 44], [23, 45, 67, 32, 10]]
[23, 45, 43, 23, 45]
[89, 90, 87, 65, 44]
43
65

```

We can also access elements using `for loop`

**Syntax**:

```
for rows in the array:
  for columns in rows:
    print(columns)

```

where,

- rows are used to iterate the row by row
- columns is used to iterate the values present in each row.

**Example:**

```
Creare 2D array with 4 rows and 5 columns
array=[[23,45,43,23,45],[45,67,54,32,45],[89,90,87,65,44],[23,45,67,32,10]]

#use for loop to iterate the array
for rows in array:
 for columns in rows:
   print(columns,end=" ")
   print()

```

**Output:**

```
23 45 43 23 45
45 67 54 32 45
89 90 87 65 44
23 45 67 32 10

```

**Don't Miss:**

- [Python OOPs: Class, Object, Inheritance and Constructor](https://www.guru99.com/python-class-objects-object-oriented-programming-oop-s.html)
- [Python JSON: Encode(dumps), Decode(loads) & Read JSON File](https://www.guru99.com/python-json.html)
- [Python enumerate() Function: Loop, Tuple & String](https://www.guru99.com/python-enumerate-function.html)
- [How to Make a Tic Tac Toe Game in Python with Code Example](https://www.guru99.com/tic-tac-toe-python.html)

## Inserting the values into the two-dimensional array

Here we are going to insert values into two dimensional array using insert() function

Syntax:

```
array.insert(index,[values])

```

where,

- the array is the input array
- the index is the row position to insert a particular row
- value are the values to be inserted into the array

**Example:** Insert to values in the array

```
#Create 2D array with 4 rows and 5 columns
array=[[23,45,43,23,45],[45,67,54,32,45],[89,90,87,65,44],[23,45,67,32,10]]

#insert the row at 5 th position
array.insert(2, [1,2,3,4,5])

#insert the row at 6 th position
array.insert(2, [1,2,3,4,5])

#insert the row at 7 th position
array.insert(2, [1,2,3,4,5])

#display
print(array)

```

**Output:**

```
[[23, 45, 43, 23, 45], [45, 67, 54, 32, 45], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [89, 90, 87, 65, 44], [23, 45, 67, 32, 10]]

```

## Updating the values into the two-dimensional array

Here are two methods for updating values in the 2-D array(list).

You can update rows by using the following syntax

```
array[row_index]= [values]

```

You can update column values inside rows by using the following syntax

```
array[row_index][column_index]= [values]

```

**Example:**

```
#creare 2D array with 4 rows and 5 columns
array=[[23,45,43,23,45],[45,67,54,32,45],[89,90,87,65,44],[23,45,67,32,10]]

#update row values in the 3rd row
array[2]=[0,3,5,6,7]

#update row values in the 5th row
array[2]=[0,3,5,6,7]

#update the first row , third column
array[0][2]=100

#update the second row , third column
array[1][2]=400

#display
print(array)

```

**Output:**

```
[[23, 45, 100, 23, 45], [45, 67, 400, 32, 45], [0, 3, 5, 6, 7], [23, 45, 67, 32, 10]]

```

## Deleting the values from two-dimensional array

You can delete rows using the `del` function

**Syntax:**

```
del array[index]

```

where,

- the array is the input array
- index refers to the row index

Example:

```
#creare 2D array with 4 rows and 5 columns
array=[[23,45,43,23,45],[45,67,54,32,45],[89,90,87,65,44],[23,45,67,32,10]]

#delete row values in the 3rd row
del array[2]

#delete row values in the 2nd row
del array[1]

#display
print(array)

```

**Output:**

```
[[23, 45, 43, 23, 45], [23, 45, 67, 32, 10]]

```

## Get the size of two-dimensional array

You can get the size of the two-dimensional array using the line() function. It will return the number of rows in the array

**Syntax**:

```
len(array)
```

**Example:**

Get the length of the two-dimensional array

```
#creare 2D array with 4 rows and 5 columns
array=[[23,45,43,23,45],[45,67,54,32,45],[89,90,87,65,44],[23,45,67,32,10]]
#display
print(len(array))

```

Output:

```
4
```

## Important Python Array (List) Methods

Here are some important Array(list) Methods

| Method | Description | Syntax | Example |
| --- | --- | --- | --- |
| Append(): | This method helps us to add an element at the end to an existing array. | array.append(value) | <pre># Adding an element using append method to the end of an array array=[1,2,3] array.append(4) print(array)</pre>Output:<pre>[1,2,3,4]</pre> |
| Clear(): | This method helps us to remove all the elements present in an array | array.clear() | <pre># Removing all the elements from an array array=[1,2,3]array.clear()</pre>Output:<pre>[]</pre> |
| Copy(): | This method helps us to copy the contents of an array to a new array | array1=array.copy() | <pre>#Copying the elements from an array to a new array array=[1,2,3] array1=[]array1=array.copy()<br>  print(array1)</pre>Output:<pre>[1,2,3]</pre> |
| Count(): | This method helps us to count the no.of occurences of a an specified element in an array | array.count(element) | <pre>#Counting the no of times an element is present in an array array=[1,2,3]print(array.count(8))</pre><pre> Output: 0</pre> |
| Extend(): | This method helps us to extend an array beyond it’s consisting elements. | array.extend(array1) | <pre>#Extending an existing array with another array array=[1,2,3] array1=[4,5,6] array.extend(array1) print(array)</pre><pre>Output: [1,2,3,4,5,6]</pre> |
| Index(): | This method helps us to find the index of an element in an array | array.index(element) | <pre>#returing the index an element in an array array=[1,2,3]print(array.index(3))</pre>Output:<pre>2</pre> |
| Insert(): | This method helps us to insert elements into an array at specified index. | array.insert(index,element) | <pre>#Inserting an element at a specified index into an array array=[1,2,3]array.insert(2,4)<br>  print(array)</pre>Output:<pre>[1,2,4,3]</pre> |
| Pop(): | This method helps us to remove an element at specified index | array.pop(index) | <pre>#Removing an element at specified index through pop methodarray=[1,2,3]<br>array.pop(2)<br>  print(array)</pre>Output:<pre>[1,2]</pre> |
| Remove(): | This method helps us to remove an particular matching element in an array. | array.remove(element) | <pre>array=[1,2,3]<br>array.remove(2)<br>  print(array)</pre>Output:<pre>[1,3]</pre> |
| Reverse(): | This method helps is to reverse the elements in an array. | array.reverse() | <pre>array=[1,2,3,4]<br>array.reverse()<br>  print(array)</pre>Output:<pre>[4,3,2,1]</pre> |

This code is editable. Click Run to Execute  

  

## FAQs

🔀 What is the difference between a 2D array and a list of lists?

In Python, a 2D array is normally implemented as a list of lists, so the two terms mean the same thing. For fast numeric work, the NumPy library offers a dedicated true array type.

🧮 How do you create a 2D array using NumPy?

Import NumPy, then pass a list of lists to numpy.array(), for example np.array(\[\[1,2],\[3,4]]). NumPy arrays support fast element-wise math, slicing, and reshaping that plain lists of lists cannot do efficiently.

⬜ How do you initialize an empty 2D array in Python?

Use a list comprehension such as \[\[0]\*cols for \_ in range(rows)]. Avoid \[\[0]\*cols]\*rows, because it repeats the same inner list reference, so editing one row accidentally changes every row.

📏 How do you find the number of rows and columns in a 2D array?

Use len(array) for the number of rows and len(array\[0]) for the columns in the first row. With NumPy, the shape attribute returns both values as a (rows, columns) tuple.

⚖️ What is the difference between a Python list and a NumPy array?

A list stores mixed data types and lives in scattered memory. A NumPy array holds one data type in contiguous memory, uses less space, and runs numeric operations much faster because they execute in C.

🔁 How do you loop through a 2D array in Python?

Use nested for loops: the outer loop iterates over each row, and the inner loop iterates over the columns inside that row. This lets you read or update every element position by position.

🤖 How can AI help me work with 2D arrays in Python?

AI assistants can generate 2D array code, explain index errors, write nested loops, and convert between a list of lists and a NumPy array, which speeds up learning and everyday data tasks.

🧠 Can GitHub Copilot generate and debug 2D array code?

Yes. GitHub Copilot autocompletes 2D array creation, indexing, and traversal from a comment, and agentic tools can refactor nested loops or spot off-by-one bugs across a file automatically.

#### Summarize this post with:

ChatGPTPerplexityGrokGoogle AI

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.**

##### Sign up for the newsletter

Subscribe for Free

You have successfully subscribed.  
Please check your inbox.

![AI-Newsletter]() Chosen by over **350,000+** professionals

[Scroll to top](#wrapper)

×

Search for:

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/python-2d-arrays.png","url":"https://www.guru99.com/images/python-2d-arrays.png","width":"700","height":"250","caption":"Python 2D Arrays","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/python-2d-array.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/python","name":"Python"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/python-2d-array.html","name":"Python 2D Arrays: Two-Dimensional List Examples"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/python-2d-array.html#webpage","url":"https://www.guru99.com/python-2d-array.html","name":"Python 2D Arrays: Two-Dimensional List Examples","dateModified":"2026-10-07T13:07:54+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/python-2d-arrays.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/python-2d-array.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/editorial","name":"Editorial Team","url":"https://www.guru99.com/author/editorial","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/favicon-new-logo.png","url":"https://www.guru99.com/images/favicon-new-logo.png","caption":"Editorial Team","inLanguage":"en-US"},"sameAs":["https://www.guru99.com/editorial-team"],"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Python","headline":"Python 2D Arrays: Two-Dimensional List Examples","description":"Array is a data structure used to store elements. An array can only store similar types of elements. A Two Dimensional is defined as an Array inside the Array. The index of the array starts with 0 and ends with a size of array minus 1.","keywords":"python","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/editorial","name":"Editorial Team"},"dateModified":"2026-10-07T13:07:54+05:30","image":{"@id":"https://www.guru99.com/images/python-2d-arrays.png"},"copyrightYear":"2026","name":"Python 2D Arrays: Two-Dimensional List Examples","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is the difference between a 2D array and a list of lists?","acceptedAnswer":{"@type":"Answer","text":"In Python, a 2D array is normally implemented as a list of lists, so the two terms mean the same thing. For fast numeric work, the NumPy library offers a dedicated true array type."}},{"@type":"Question","name":"How do you create a 2D array using NumPy?","acceptedAnswer":{"@type":"Answer","text":"Import NumPy, then pass a list of lists to numpy.array(), for example np.array([[1,2],[3,4]]). NumPy arrays support fast element-wise math, slicing, and reshaping that plain lists of lists cannot do efficiently."}},{"@type":"Question","name":"How do you initialize an empty 2D array in Python?","acceptedAnswer":{"@type":"Answer","text":"Use a list comprehension such as [[0]*cols for _ in range(rows)]. Avoid [[0]*cols]*rows, because it repeats the same inner list reference, so editing one row accidentally changes every row."}},{"@type":"Question","name":"How do you find the number of rows and columns in a 2D array?","acceptedAnswer":{"@type":"Answer","text":"Use len(array) for the number of rows and len(array[0]) for the columns in the first row. With NumPy, the shape attribute returns both values as a (rows, columns) tuple."}},{"@type":"Question","name":"What is the difference between a Python list and a NumPy array?","acceptedAnswer":{"@type":"Answer","text":"A list stores mixed data types and lives in scattered memory. A NumPy array holds one data type in contiguous memory, uses less space, and runs numeric operations much faster because they execute in C."}},{"@type":"Question","name":"How do you loop through a 2D array in Python?","acceptedAnswer":{"@type":"Answer","text":"Use nested for loops: the outer loop iterates over each row, and the inner loop iterates over the columns inside that row. This lets you read or update every element position by position."}},{"@type":"Question","name":"How can AI help me work with 2D arrays in Python?","acceptedAnswer":{"@type":"Answer","text":"AI assistants can generate 2D array code, explain index errors, write nested loops, and convert between a list of lists and a NumPy array, which speeds up learning and everyday data tasks."}},{"@type":"Question","name":"Can GitHub Copilot generate and debug 2D array code?","acceptedAnswer":{"@type":"Answer","text":"Yes. GitHub Copilot autocompletes 2D array creation, indexing, and traversal from a comment, and agentic tools can refactor nested loops or spot off-by-one bugs across a file automatically."}}]}],"@id":"https://www.guru99.com/python-2d-array.html#schema-1139286","isPartOf":{"@id":"https://www.guru99.com/python-2d-array.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/python-2d-array.html#webpage"}}]}
```
