In Python, what is difference between Array and List?

0 votes
Mar 15, 2019 in Python by Shabnam
• 920 points

3 answers to this question.

+1 vote

Lists and arrays are used in Python to store data(any data type- strings, integers etc), both can be indexed and iterated also. Difference between lists and arrays are the functions that you can perform on them like for example when you want to divide an array by 4, the result will be printed on request but in case of a list, python will throw an error message. Here's how it works: 

Arrays need to be declared whereas lists do not need declaration because they are a part of Python's syntax. This is the reason lists are  more often used than arrays. But in case you want to perform some arithmetic function to your list, one should go with arrays instead. 

If you want to store a large amount of data, then you should consider arrays because they can store data very compactly and efficiently.

answered Mar 15, 2019 by Taj
• 1,060 points

edited Mar 18, 2019 by Omkar
0 votes
Python does not have native array data structure,but it has the list which is mutable which means we can modify the content present within the list.We can store data of heterogeneous datatypes.List is much more general and can be used as a multidimensional array quite easily.
answered Mar 19 by chirag
• 180 points
0 votes

In Python an array.array is a 1-dimensional linear array; it is variable length (so it doesn't necessarily pack data together in memory), but it can only hold data of one fixed-size type, and so cannot hold other containers (for instance other array.arrays). This constraint enables the interpreter to efficiently allocate memory, as whenever you're going to grow the array substantially it needs to only pre-allocate space for more of a known-width data type. So, if you know your data type ahead of time, using an array.array can be quite a bit more memory efficient.

Contrast that with Python's list, which is variable width but can also hold variable-width data types, and can also therefore contain N-dimensions (ie you can make lists of lists). This is much less memory-efficient, as the interpreter needs to pre-allocate quite a bit of memory to allow it to grow performantly.

answered Apr 13 by beenmeckel
• 180 points

Related Questions In Python

+1 vote
1 answer

What is the difference between range and xrange functions in Python 2.X?

xrange only stores the range params and ...READ MORE

answered Aug 22, 2018 in Python by Priyaj
• 57,660 points
0 votes
3 answers
+2 votes
2 answers

What is the difference between print and return in python?

Return statements end the execution of a ...READ MORE

answered Aug 25, 2019 in Python by anonymous
0 votes
0 answers

What is the difference between isdigit, isnumeric and isdecimal in python?

Can you give examples for each of ...READ MORE

May 31, 2019 in Python by Waseem
• 4,540 points
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,366 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,800 points
0 votes
1 answer

What is difference between "inplace = True" and "inplace = False?

Hi, Both inplace= true and inplace = False ...READ MORE

answered Aug 9, 2019 in Python by Taj
• 1,060 points