What is the difference between python lists and arrays?

0 votes
Are python arrays same as lists?
Jun 7 in Python by anonymous
54 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
• 24,320 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,900 points
394 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,900 points
239 views
+1 vote
1 answer

What is the difference between print and return in python?

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

answered Aug 25 in Python by anonymous
117 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
• 4,480 points
262 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
• 2,960 points
77 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
• 2,960 points
142 views
0 votes
1 answer

What is the key difference between self in ruby and self in python?

Ruby and Python are actually very different languages (although ...READ MORE

answered Jul 30 in Python by Mohammad
• 3,060 points
22 views
0 votes
4 answers