What is the difference between python lists and arrays

0 votes
Are python arrays same as lists?
Jun 7, 2019 in Python by anonymous
1,546 views

2 answers to this question.

0 votes

Hi, Arrays and lists both are used to store data in Python, but they don't serve exactly the same purposes. The main difference between a list and an array is the functions that you can perform to them.  It does take an extra step to use arrays because they have to be declared while lists don't because they are part of Python's syntax, so lists are generally used more often between the two, which works fine most of the time.

So, python lists are very flexible and can hold completely heterogeneous, arbitrary data, and they can be appended to very efficiently, in amortized constant time. If you need to shrink and grow your array time-efficiently and without hassle, you can simply use lists. But they use a lot more space than arrays. While the array, on the other hand, can hold only homogeneous data, all of the same type, and so it uses only sizeof(one object) * length bytes of memory. 

For example, you can divide an array of numbers by 3, and each number in the array will be divided by 3 and the result will be printed if you request it. If you try to divide a list by 3, Python will tell you that it can't be done, and an error will be thrown.

answered Jun 9, 2019 by Abha
• 28,140 points
0 votes
Python arrays and lists have the same way of storing data but the key difference between them is that lists can store any type of data whereas arrays store single data type elements.
And because of this difference,  other than a few operations like sorting and looping,  operations performed on these data structures are different.
To create arrays in python,  you will need to import the array module. However these arrays are very generic and they are not the same as NumPy arrays.
answered Jun 11, 2019 by Nisa
• 1,090 points

Related Questions In Python

0 votes
5 answers
0 votes
1 answer

What is the difference between sets and lists in Python?

Lists can contain duplicates but sets cannot Sets ...READ MORE

answered Feb 9, 2022 in Python by Dev
• 6,000 points
1,140 views
0 votes
1 answer

What is the difference between Python and IPython?

There are few differences between Python and ...READ MORE

answered Jul 26, 2018 in Python by Priyaj
• 58,020 points
4,005 views
+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
+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,255 views
0 votes
1 answer

What is the difference between str() and repr() functions in Python?

str() is mostly used to create output ...READ MORE

answered Jul 8, 2019 in Python by Arvind
• 3,050 points
1,613 views
0 votes
1 answer

What is the difference between print and pprint in Python?

As per the documentation,  The pprint module provides a capability ...READ MORE

answered Jul 8, 2019 in Python by Arvind
• 3,050 points
6,875 views
0 votes
4 answers
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