---
title: "Array methods function in Python?"  
description: "Array methods function in Python?"  
author: "Prakash nidhi Verma"  
published: 2018-07-04  
updated: 2023-05-03  
canonical: https://www.mindstick.com/interview/23453/array-methods-function-in-python  
category: "python"  
tags: ["python-3.4", "python"]  
reading_time: 2 minutes  

---

# Array methods function in Python?

Method function in python :

append()

clear()

copy()

count()

extend()

index()

insert()

pop()

remove()

reverse()

sort()

## Answers

### Answer by Aryan Kumar

In Python, arrays are implemented using the **array** module, which provides a range of methods for working with arrays. Some of the most commonly used methods are:

1. **append()**: adds an element to the end of the array.
2. **extend()**: adds the elements of an iterable (e.g., another array, list, or tuple) to the end of the array.
3. **insert()**: inserts an element at a specific position in the array.
4. **remove()**: removes the first occurrence of an element from the array.
5. **pop()**: removes and returns the element at a specific position in the array.
6. **index()**: returns the index of the first occurrence of an element in the array.
7. **count()**: returns the number of occurrences of an element in the array.
8. **reverse()**: reverses the order of the elements in the array.
9. **sort()**: sorts the elements in the array in ascending order (or in descending order if the **reverse** argument is set to **True**).

```python
import array
# Create an array of integers
my_array = array.array('i', [1, 2, 3, 4, 5])
# Append an element to the array
my_array.append(6)
# Insert an element at position 1
my_array.insert(1, 0)
# Remove the first occurrence of the element 3
my_array.remove(3)
# Print the index of the first occurrence of the element 4
print(my_array.index(4))
# Reverse the order of the elements in the array
my_array.reverse()
# Sort the elements in the array in descending order
my_array.sort(reverse=True)
# Print the final array
print(my_array)
```

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()**. Finally, we print the contents of the modified array.

### Answer by Prakash nidhi Verma

Method function in python :

append()

clear()

copy()

count()

extend()

index()

insert()

pop()

remove()

reverse()

sort()


---

Original Source: https://www.mindstick.com/interview/23453/array-methods-function-in-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
