How to declare an array in Python?

How to declare an array in Python?

In Python, you can declare an array using square brackets.

For example, my_array = [] creates an empty array.

You can declare an array in Python using the array module.

First, you need to import the array module (import array). Then, you can create an array with a specific data type like this: my_array = array.array(‘i’, [1, 2, 3, 4, 5]), where ‘i’ indicates the data type (integer in this case).

Another way to declare an array in Python is to use the numpy library. First, you need to install numpy (pip install numpy).

Then, you can create an array using numpy like this: import numpy as np and my_array = np.array([1, 2, 3, 4, 5]). Numpy arrays offer more functionality and flexibility compared to regular Python arrays.