Python array methods are functions available for manipulating arrays created using the array module, which stores homogeneous data types efficiently. These methods allow you to add, remove, search, and modify elements in an array.

Core Array Methods

  • append(x): Adds an element x to the end of the array.

  • extend(iterable): Appends all elements from an iterable (e.g., list, tuple) to the end of the array.

  • insert(i, x): Inserts element x at index i.

  • remove(x): Removes the first occurrence of element x.

  • pop([i]): Removes and returns the element at index i (or the last element if no index is specified).

  • index(x[, start[, stop]]): Returns the index of the first occurrence of x within the specified range.

  • count(x): Returns the number of times x appears in the array.

Utility and Conversion Methods

  • reverse(): Reverses the order of elements in the array.

  • tolist(): Converts the array to a standard Python list.

  • fromlist(list): Appends elements from a list to the array.

  • tobytes(): Returns the array's contents as a bytes object.

  • frombytes(buffer): Appends items from a bytes-like object to the array.

  • fromfile(f, n): Reads n items from file object f and appends them.

  • tofile(f): Writes all items to file object f.

Important Notes

  • Arrays in Python are homogeneous—all elements must be of the same type, defined by a type code (e.g., 'i' for integers, 'f' for floats).

  • The array module is distinct from standard lists, which are more flexible but less memory-efficient.

  • For numerical computing, NumPy arrays are preferred, offering additional methods like .sum(), .mean(), .reshape(), and .sort().

💡 Example:

import array
arr = array.array('i', [1, 2, 3])
arr.append(4)
arr.insert(1, 5)
print(arr.tolist())  # Output: [1, 5, 2, 3, 4]
🌐
W3Schools
w3schools.com › python › python_ref_list.asp
Python List/Array Methods
Python has a set of built-in methods that you can use on lists/arrays.
🌐
MindStick
mindstick.com › interview › 23453 › array-methods-function-in-python
Array methods function in Python? – MindStick
June 25, 2018 - This example creates an array of integers using the array() function from the array module. We then use several of the array methods to modify the array, including append(), insert(), remove(), index(), reverse(), and sort().
Discussions

Python arrays
If you're just learning, just use lists. They have essentially the same interface (meaning everything you can do to an array, you can do to a list), and while they are somewhat less performant, if you're just poking around, that's probably not important. If the performance is a consideration, use NumPy. If you want really fine control over exactly how memory is laid out, use a different language. More on reddit.com
🌐 r/learnpython
13
3
March 3, 2025
What is Python's list.append() method WORST Time Complexity? It can't be O(1), right?
I've read on Stackoverflow that in Python Array doubles in size when run of space It's actually not double, but it does increase proportional to the list size (IIRC it's about 12%, though there's some variance at smaller sizes). This does result in the same asymptotics though, so I'll assume doubling in the following description for simplicity. So basically it has to copy all addresses log(n) times. Not quite. Suppose we're appending n items to an empty vector. We will indeed do log(n) resizes, so you might think "Well, resizes are O(n), so log(n) resizes is n log(n) operations, which if we amortize over the n appends we did means n log(n)/n, or log(n) per append". However, there's a flaw in this analysis: we do not copy "all addresses" each of those times. Ie. the copies are not O(n). Sure, the last copy we do will involve copying n items, but the one before it only copied n/2, and so on. So we actually do 1 + 2 + 4 + ... + n copies, which sums to 2n-1. Divide that by n and you get ~2 operations per append - a constant. I assume since it copies addresses, not information We are indeed only copying the pointer, but this doesn't really matter for the complexity analysis. Even if it was copying a large structure, that'd only increase the time by a constant factor. Does that mean that O(1) is the average time complexity? It's the amortized worst case complexity (ie. what happens over a large number of operations). While any one operation can indeed end up doing O(n) operations, there's an important distinction that over a large number of operations, you are guaranteed to only be O(1), which is a distinction just talking about average case wouldn't capture. More on reddit.com
🌐 r/learnpython
11
3
October 26, 2022
__getitem__ method in 2D array class.
The signature of __getitem__ is __getitem__(self, key) which means that the signature of your function is not valid. Since __getitem__ only accepts a single key, and you need to provide row and col to index into your two-dimensional array, you have two choices: bundle up row and col in a tuple (ie as a single value), or if you want to be able to use something like myarray[x][y], you need to think about how that would be implemented. Some clues. Version one, using a tuple: def __getitem__(self, row_col_as_tuple): row = .... ? col = .....? #How would you obtain `row` and `column` from `row_col_as_tuple`? return ?? Version two, allowing list-like access eg myarray[1][2]. Think what this is actually doing; it first calls myarray[1] and then calls [2] on whatever myarray[1] returns. That is, it is actually making two calls to __getitem__, and consequently, whatever object __getitem__ returns, that object itself must be a class that with a __getitem__ method. def __getitem__(self, key): # where `key` in an integer value = self._arr[?] return ?? # Here you have to return a class with a __getitem__ method that has access to `self._arr`. More on reddit.com
🌐 r/learnpython
5
3
September 14, 2014
Is it bad practice to over rely on arrays / lists (JS/python)
Perfectly fine to use them if problem at hand makes sense. Just remember they are not the only data structure and sometimes others are better for certain situations: find yourself removing duplicates from your array? Maybe a Set that ensures uniqueness is a better option. find yourself needing to access items in your array often based on a certain value? Perhaps a Map with its fast key-value access is a good choice. …etc… More on reddit.com
🌐 r/learnprogramming
24
30
September 9, 2021
🌐
NumPy
numpy.org › doc › 2.4 › reference › arrays.html
Array objects — NumPy v2.4 Manual
Methods · Defining new types · Data type objects (dtype) Specifying and constructing data types · Checking the data type · dtype · Data type promotion in NumPy · Detailed behavior of Python scalars · Numerical promotion · Exceptions to the general promotion rules · Promotion of non-numerical datatypes · Details of promoted dtype instances · Iterating over arrays ·
🌐
Python
docs.python.org › 3 › library › array.html
array — Efficient arrays of numeric values
If given a bytes or bytearray object, the initializer is passed to the new array’s frombytes() method; if given a Unicode string, the initializer is passed to the fromunicode() method; otherwise, the initializer’s iterator is passed to the extend() method to add initial items to the array.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.array.html
numpy.array — NumPy v2.4 Manual
If None, a copy will only be made if __array__ returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy any of the other requirements (dtype, order, etc.). Note that any copy of the data is shallow, i.e., for arrays with object dtype, the new array will point to the same objects.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-arrays
Python Arrays - GeeksforGeeks
1 week ago - ... In Python, an array is used to store multiple values or elements of the same datatype in a single variable. The extend() function is simply used to attach an item from iterable to the end of the array.
🌐
GeeksforGeeks
geeksforgeeks.org › python › array-python-set-1-introduction-functions
Array Module in Python - GeeksforGeeks
August 2, 2025 - Example: It demonstrates to use insert() method to add an element at a specific position in an array.
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › python-array-tutorial-define-index-methods
Python Array Tutorial – Define, Index, Methods
January 31, 2022 - In this article, you'll learn how to use Python arrays. You'll see how to define them and the different methods commonly used for performing operations on them. The article covers arrays that you create by importing the array module. We won't cover N...
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.3 documentation
Tuples can be used as keys if they contain only strings, numbers, or tuples; if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key. You can’t use lists as keys, since lists can be modified in place using index assignments, slice assignments, or methods like append() and extend().
🌐
freeCodeCamp
freecodecamp.org › news › how-arrays-work-in-python
How Arrays Work in Python – Array Methods Explained with Code Examples
July 12, 2023 - In this tutorial, you'll learn what an array is in Python. You'll also learn some possible ways to add elements to an existing array. In Python, there is no need to use a specific data type for arrays. You can simply use a list with all the attribut...
🌐
Readthedocs
pythontutorial-wdyds.readthedocs.io › en › latest › 3_Lists_Arrays › lists_arrays.html
4. Lists and Arrays — A Python Tutorial for Data Scientists 2.0 documentation
These notes on lists have thus ... with a Python list, which you should try and remember. That is, you should know that there’s a function for sorting lists, but it’s ok if you don’t remember the exact syntax off the top of your head. For a good reference on list methods, see ...
🌐
Bizmia LLC
hellobizmia.com › home › how to handle python arrays like a pro – best practices & methods
Array in Python: Creation, methods, performance, and examples
August 13, 2025 - Through NumPy, you can use type-restricted arrays, standard lists, or multidimensional numerical arrays. Some useful array methods are remove ( ), pop ( ), append ( ), reverse ( ) for lists, and ,mean ( ), .reshape ( ), and .sum ( ) for NumPy.
🌐
W3Schools
w3schools.com › python › gloss_python_array_methods.asp
Python Array Methods
Python has a set of built-in methods that you can use on lists/arrays.
🌐
W3Schools
w3schools.com › python › python_dsa_lists.asp
Python Lists and Arrays
Sometimes we want to perform actions that are not built into Python. Then we can create our own algorithms. For example, an algorithm can be used to find the lowest value in a list, like in the example below: Create an algorithm to find the lowest value in a list: my_array = [7, 12, 9, 4, 11, 8] minVal = my_array[0] for i in my_array: if i < minVal: minVal = i print('Lowest value:', minVal) Try it Yourself »
🌐
Medium
medium.com › @jvolpe721 › python-array-methods-414eb93a600a
Python- Array Methods. (some simple array methods- for… | by Jennifer Volpe | Medium
May 1, 2018 - Python- Array Methods (some simple array methods- for beginners!) Create an Array We can create a Python array with comma separated elements between square brackets[]. Access elements of an Array We …
🌐
Cach3
w3schools.com.cach3.com › python › gloss_python_array_methods.asp.html
Python Array Methods
Python has a set of built-in methods that you can use on lists/arrays.
🌐
Tutorialspoint
tutorialspoint.com › home › python › python array methods
Python Array Methods
February 21, 2009 - The array class defines several methods, including adding and removing elements, obtaining information about the array, manipulating array elements, and converting arrays to and from other data types.
🌐
Bhrighu
bhrighu.in › blog › array-in-python-examples-and-comparison
Array in Python: Full Guide with Examples & Comparison
Understanding an array in Python is crucial for writing efficient and scalable code. Arrays help manage collections of data in a structured and predictable way. Whether you're manipulating lists for simple scripts, using the array module for memory-efficient tasks, or working with NumPy arrays for complex data analysis, each method ...
🌐
W3Schools
w3schools.com › python › python_arrays.asp
Python Arrays
You can use the for in loop to loop through all the elements of an array. ... You can use the append() method to add an element to an array.
🌐
Reddit
reddit.com › r/learnpython › python arrays
r/learnpython on Reddit: Python arrays
March 3, 2025 -

I'm following roadmap.sh/python to learn python. I'm at the DSA section.

I understand the concept of arrays in DSA, but what I don't understand is how to represent them in Python.

Some tutorials I've seen use lists to represent arrays (even though arrays are homogeneous and lists are heterogeneous).

I've seen some other tutorials use the arrays module to create arrays like array.array('i') where the array has only integers. But I have never seen anybody use this module to represent arrays.

I've also seen some tutorials use numpy arrays. Which I don't understand their difference from the normal arrays module.

What should I use to represent arrays?

So far I've solved a couple of arrays exercises using Python lists.