Can anyone explain the basic difference between list and array? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can anyone explain the basic difference between list and array?

27th Aug 2019, 5:40 PM
Chandan Kumar
Chandan Kumar - avatar
5 Answers
+ 5
An array is a storage with a fixed size. Once created, you cannot change the size. But you can delete and add elements to a list on runtime. To get a similar effect for the array with size 'n' you have to create an array with size 'n+1', copy the n elements inside this and add your new element to the n+1th place. :)
27th Aug 2019, 5:50 PM
Tom Hammerbacher
Tom Hammerbacher - avatar
+ 5
In addition to Tom Hammerbacher I want to say that an array usually only stores elements of the same type whereas lists don't necessarily have that constraint. In Python there is actually no data structure called array in the standard lib. Peeps use the module numpy for that because mathematical operations on numpy arrays are much faster (and more convenient) than on lists.
27th Aug 2019, 6:47 PM
Thoq!
Thoq! - avatar
+ 3
Seb TheS Darn, u r actually right. Don't know how they have kept it secret from me for the last 3 years. Probably because noone is using it. Its use seems to be limited to the few cases where u need a 1d array but don't want to do any math on it.
27th Aug 2019, 10:42 PM
Thoq!
Thoq! - avatar
+ 2
Thoq! Isn't there a module called "array" in the standard library?
27th Aug 2019, 9:43 PM
Seb TheS
Seb TheS - avatar
+ 1
array is a similar data type and list a disimilar data type array is a static and list is a daynamic
28th Aug 2019, 1:57 PM
Shivam