forlooptanzania / dive-into-python3

Rejoicing, diving in, and investigating Python 3 together!
7 stars 0 forks source link

What is the difference between python lists and arrays? #6

Open chrisoemma opened 4 years ago

chrisoemma commented 4 years ago

What is the difference between python lists and arrays?

I understand that we can treat lists as arrays, but, what happens when I create an array using the array module?

joshuamabina commented 4 years ago

Lists vs Arrays?

Python lists and arrays are very similar in that they are both used to store a collection of data. This entails, most operations that can be performed on a typical a c-like array can be performed on any python list.

The main difference between python lists and arrays is that, lists can works with data of different numeric types while arrays must work with data of one numeric type.

When to Use What?

Generally, I would use lists in most cases as they are natively supported and widely used by other libraries. However, I would definitely use arrays if the case is to work with data where their numeric type matters and needs to be the same.

Further Reading

  1. Python: Array v. List

  2. Python List vs. Array - when to use?