1. Help Center
  2. Python Programming

What is the difference between Python Arrays and lists?

List: A list in Python is a collection of items which can contain elements of multiple data types, which may be either numeric, character logical values, etc. It is an ordered collection supporting negative indexing. A list can be created using [] containing data values.
Contents of lists can be easily merged and copied using python’s inbuilt functions.

list = [3, 6, 9, 12]
print(list)
print(type(list))
[3, 6, 9, 12]
<class 'list'>

Array: An array is a vector containing homogeneous elements i.e. belonging to the same data type. Elements are allocated with contiguous memory locations allowing easy modification, that is, addition, deletion, accessing of elements. In Python, we have to use the array module to declare arrays.

array_1 = arr.array("i", [3, 6, 9, 12])
print(array_1)
print(type(array_1))
array('i', [3, 6, 9, 12])
<class 'array.array'>