0 votes
in Python by
Narrate the difference between Python arrays and lists.

1 Answer

0 votes
by
One of the most common Python interview question. In Python, both arrays and lists are used to store data. However,

Arrays can only contain elements of the same data types, meaning the data types of an array should be homogeneous.

Lists can contain elements of different data types, which means that the data types of lists can be heterogeneous. Lists consume much more memory than arrays.

Here’s an example:

import array as arr

My_Array=arr.array(‘i’,[1,2,3,4])

My_list=[1,’abc’,1.20]

print(My_Array)

print(My_list)

Related questions

0 votes
asked Nov 15, 2020 in Python by rajeshsharma
0 votes
asked Jun 28, 2020 in Python by Robindeniel
...