Python List Vs Python Array in a nutshell
Python List is amazing
2 min read
Do you know that Python has a built-in array module to declare arrays? You don't have to install NumPy, unless you are not playing with complex array and
Python List is a built-in data structure, which can contain one or more data types, like
You can even store a list inside a
list, i.e. nested lists.
my_empty_list =  my_list = [1, 'Gaurav', [2, 4, 6]]
But Python lists consume large memory size for data but on the other hand these are flexible, efficient for CRUD operations.
Python Arrays are sequence types and behave very much like lists, except that the type of objects stored in them is constrained.
In Python, the type is specified at
object creation time by using a type code, which is a single character. We can create a Python Array using Python's built-in
import array # Syntax: array.array(typecode, [values]) my_empty_array = array.array('i', ) my_array = array.array('i', [1, 23, 45])
Python Array takes less space in memory, supports negative indexing but at the same time, can only store same data types, less flexible than lists, because modifications are expensive
For more on Python Arrays, you can check out official documentation link here: https://docs.python.org/3/library/array.html
For more such crispy blogs daily, follow Dev.Junction, subscribe to our newsletter and get notified.
- LinkedIn: https://www.linkedin.com/in/mnamegaurav/
- YouTube: https://www.youtube.com/c/devjunction
- Website: https://gaurav.devjunction.in/
- GitHub: https://github.com/mnamegaurav
- Instagram: https://www.instagram.com/mnamegaurav/
- Twitter: https://twitter.com/mnamegaurav
Did you find this article valuable?
Support Dev.Junction by becoming a sponsor. Any amount is appreciated!