In Python what is difference between Array and List

+1 vote
Mar 15, 2019 in Python by Shabnam
• 930 points
152,784 views

4 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.

Hope it helps!!

If you need to know more about Python, It's recommended to join Python course today.

Thanks!

answered Mar 15, 2019 by Taj
• 1,080 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, 2020 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, 2020 by beenmeckel
• 180 points
0 votes

Lists

  • Python lists are very flexible and can hold arbitrary data.

  • Lists are a part of Python’s syntax, so they do not need to be declared first.

Arrays

  • Python arrays are just a thin wrapper on C arrays.

  • Arrays need to first be imported, or declared, from other libraries (i.e. numpy).

answered Dec 9, 2020 by anonymous
• 82,840 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
• 58,020 points
2,393 views
0 votes
5 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 26, 2019 in Python by anonymous
8,034 views
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
2,254 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 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,790 points
4,067 views
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,080 points
17,124 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP