What is the difference between python lists and arrays?

0 votes
Are python arrays same as lists?
Jun 7 in Python by anonymous
24 views

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 9,330 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
• 640 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,140 points
158 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,140 points
92 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
• 2,710 points

edited May 24 by Omkar 11 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
• 2,710 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,116 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
77 views
0 votes
1 answer

What is the difference between re.search and re.match?

The theoritical approach can be this way, re.match is ...READ MORE

answered Aug 10, 2018 in Python by Priyaj
• 56,140 points
186 views
0 votes
1 answer
0 votes
4 answers

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.