Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
No results
  • About AskPython
  • Blog
  • Contact Me
  • Free Online Developer Tools Hub
  • Home
  • Meet the Team
  • Privacy Policy
  • Python
  • Python Course for Beginners Online FREE
  • Python Tutorial – Mega Index
  • Terms and Conditions

🚀 Supercharge your YouTube channel's growth with AI.

Try YTGrowAI Free
  • Home
  • Blog
  • About AskPython
  • Python Course
  • Start Here

Are Arrays Mutable in Python?

  • Adrita DasAdrita Das
  • February 27, 2022
  • Python Array
Are Arrays Mutable in Python?

We can classify Python objects into two major categories i.e mutable and immutable objects. Mutable objects are those which can be changed or modified once they are created whereas immutable objects cannot be altered once they are created. Arrays come under the category of mutable objects. In this article, we will learn about arrays and their mutability, and the operations you can perform on arrays. So let’s get started!

What Are Arrays in Python?

An array is a data structure in Python that stores a collection of similar types of objects. The objects in an array are indexed by a tuple of positive integers. They can be multi-dimensional and very useful for scientific computing.

For example:

import numpy as np
list=[1,2,3,4]
arr = np.array(list)
print(arr)

Output:

[1 2 3 4]

In the above example, we have created a 1-D array from a list.

You can access the array elements by the following method.

import numpy as np
list=[1,2,3,4]
arr = np.array(list)
print("First element of array is:",arr[0]) 
print("Last element of array is:",arr[-1])

Output:

First element of array is: 1
Last element of array is: 4

Now we will look at the mutable properties of an array.

Mutable Properties of Array

Now we will see what all changes we can make in array with examples.

Inserting Elements in an Array

The insert function helps you to insert elements in an array. The function takes up two arguments which are the index position where you want to insert the element and the value of the element.

import array as np
 
a = np.array('i', [1, 2, 3])

#using insert function
a.insert(1, 4)
print(a)

Output:

array('i', [1, 4, 2, 3])

Modifying Elements in an Array

You can modify the elements in an array with the help of the following code. 

import array as np
 
a = np.array('i', [1, 2, 3])

#using insert function
a[1]=9
print(a)

Output:

array('i', [1, 9, 3])

You need to specify the index position of the element you want to modify.

Popping an Element in an Array

The pop() function will help you in popping an element out. You need to specify the index position of the element you want to pop. This function acts similar to the delete operation.

import array as np
 
a = np.array('i', [1, 2, 3])

#using pop function
a.pop(1)
print(a)

Output:

array('i', [1, 3])

Deleting or Removing Elements From an Array

The remove() function will help you to remove elements from an array. You have to specify the value of the element you want to remove.

import array as np
 
a = np.array('i', [1, 2, 3])

#using remove function
a.remove(3)
print(a)

Output:

array('i', [1, 2])

Reversing an Array

The simple reverse() function will help you in reversing an array.

import array as np
 
a = np.array('i', [1, 2, 3])

#using remove function
a.reverse()
print(a)

Output:

array('i', [3, 2, 1])

Conclusion

In summary, we learned that arrays are mutable and can be modified or altered after they are created. It is very crucial that you understand the basic array operations as arrays can be extremely useful in scientific computing.

Adrita Das
Adrita Das
Articles: 24
Boolean Indexing in Python – A Quick Guide
Previous Post Boolean Indexing in Python - A Quick Guide
Next Post Difference Between Pandas Dataframe and Numpy Arrays
Difference Between Pandas Dataframe and Numpy Arrays

Related Posts

Add Elements to Array Python

Add Elements to Array Python

  • November 22, 2026
How to Sort Array in Python

How to Sort Array in Python

  • November 19, 2026
Python Two Dimensional Array: Create and Use

Python Two Dimensional Array: Create and Use

  • November 16, 2026

Partner Websites

  • GoLangDocs
  • LinuxForDevices
  • CodeForGeek

Popular Categories

  • Python Programming
  • Python Modules
  • OOPS in Python
  • Python Programming Examples
  • Strings in Python

Hall of Fame

  • Python Programming
  • OOPS in Python
  • Creating Python Modules
  • Args and Kwargs in Python
  • Python Dictionary (Dict) Tutorial
  • Python List – 15 Things You MUST Know
  • Python Set – Things You MUST Know
  • Python String Functions: Methods by Task

Important Links

  • Home
  • Python Course
  • Start Here
  • Blog
  • About AskPython
Latest posts
  • np.linalg.eig: Eigenvalues and Eigenvectors
  • What Does %s Mean in a Python Format String?
  • How to Use np.sin() in NumPy
  • cv2.imread: Load Images with OpenCV
  • pd.read_json: Read JSON Into a DataFrame

Copyright © 2026 - AskPython. All rights reserved.