Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

If you are creating a 1d array, you can implement it as a List, or else use the 'array' module in the standard library. I have always used Lists for 1d arrays.

What is the reason or circumstance where I would want to use the array module instead?

Is it for performance and memory optimization, or am I missing something obvious?

1 Answer

0 votes
by (106k points)

Actually this question is very obvious as in Python we have List data structure which is built-in data structure in Python and if you want to make an array data structure you need to take the help of pandas module so I am clearing all the doubts regarding List and Array in Python when to use and all other things as well:-

So when you use Python lists, which is very flexible and can hold completely heterogeneous arbitrary data, and lists can be appended to very efficiently, in amortized constant time. You can easily shrink and grow your list efficiently without any hassle why because it is an in-built data structure in Python and Python provides many operations for List.

To access Arrays in Python we need to import pandas module and from that module, we can construct our array. One advantage of using arrays is that it takes less space as compared to the List.

If you are doing any mathematical problem in Python then it is advised to use List because if you want to use the array then you will need to use NumPy or Pandas module that will increase the complexity of the code.

Moreover, in Python, we prefer to use the List because almost it has all the features which an array has and also it is built-in data structure in Python so Python provides many operations on it which will make your task easy.

Related questions

Browse Categories