r/PythonLearning • u/couriouscosmic • Nov 06 '25
Discussion why arrays modules need to be imported
in python,unlike lists which are built in why arrays module has to imported to use them what were the thought process of the one who designed the language that way
6
u/American_Streamer Nov 06 '25
Arrays aren’t built in, because Python’s default abstraction for sequences is the high-level, flexible list; in contrast, the array module is a more low-level optimization tool, so it’s tucked away in the standard library instead of the core language.
1
u/princepii Nov 07 '25
may i awk why even u use arrays in python? what was or is your use case for it?
1
1
u/gdchinacat Nov 07 '25
Use list until you know for certain you need more performance. Then look into numpy. I've used python full time for 20 years and have never used arrays, and only seen it used a couple of times. It is probably not what you want.
1
u/couriouscosmic Nov 07 '25
yes simply asked why it's the opposite in python unlike in other languages
2
2
u/games-and-chocolate Nov 07 '25
interesting post, I am going to try arrays now!
To check the performace difference. Only used : list, dictionary. python beginner tutorials never / hardly show arrays.
3
u/warhammercasey Nov 06 '25
Why do you need arrays specifically over lists? Python is designed around using lists to serve the same purpose as arrays in other languages. The only real reason I could think of to use an array is performance, but at that point it’s better to just use something more tailored to your application like a numpy array.
2
u/queerkidxx Nov 07 '25 edited Nov 07 '25
I had no idea there was a lower level array module in Python. Looks like it can only be used on statically sized objects and is dynamically sized.
I wouldn’t use arrays unless you really need the extra performance. That is, you either know for sure at the start that you’ll only need to store statically sized types at the start and that this array is going to be a bottleneck or you find in testing that the list is a bottleneck.
Really though, for at least my use case if I was doing something where I’d think about using arrays I’d either be using a native compiled library for the performance or just use rust or something.
But to answer your question: Lists in Python serve the role of the arrays module. And for most use cases are more than efficient. The arrays module provides a more limited, performance oriented implementation of a lower level ordered collection that will be more performant but at the cost of exposing the more lower level concept of statically vs dynamically sized types(hence the limitation of what can be stored there and exposing C types).
This is not ergonomic at all because these types do not really exist in python and requires usage of “type codes”. This just kinda sucks to use in Python and is only needed in niche circumstances. Really, I’d only recommend using this collection if you can’t switch to a lower level langauge or at least make your own library. But I’m sure it comes in handy.
For all other use cases, lists are arrays the distinction in terminology is almost non existent across most languages. Use a list.