What is the difference between python lists and arrays?

0 votes
Are python arrays same as lists?
Jun 7 in Python by anonymous
32 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 8 by Abha
• 15,300 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 10 by Nisa
• 1,090 points

Related Questions In Python

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
• 56,160 points
192 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
• 56,160 points
131 views
0 votes
0 answers

What is the difference between print and return in python?

If we get the same output why ...READ MORE

May 23 in Python by Waseem
• 3,320 points

edited May 24 by Omkar 19 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 in Python by Waseem
• 3,320 points
37 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 in Python by Arvind
• 1,290 points
23 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 in Python by Arvind
• 1,290 points
19 views
0 votes
1 answer

What is the difference between list and tuple?

Lists are mutable(values can be changed) whereas ...READ MORE

answered May 4, 2018 in Python by aayushi
• 750 points
1,210 views
+1 vote
2 answers

What is the difference between classes and labels in machine learning?

Classes and Labels both are almost same things ...READ MORE

answered Apr 3 in Python by SA
• 1,030 points
86 views
0 votes
4 answers