Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)

I am learning python but cannot understand the differences between arrays and list in python. Is there a difference between these two and if so then what is the difference?

1 Answer

0 votes
by (25.1k points)

An array is basically a data type that can hold multiple values of the same data type. In languages like C++ and Java you can create an array of any datatype you wish like Integer or String etc. In an array you can only store values of one type, e.g. in an Integer array can only hold Integer values and not string or any other data type. To create an array you will need to firstly import array module inside your python file and then user it's array method and describe it's type like integer as it's first argument and then a list that contains some members of the same data types e.g.:

import array

array.array('i', [1, 2, 3]) # i means that it is an integer array

In python there is data type called list that can hold multiple values of different data types. You can store an integer, string, object etc. Inside a list. e.g."

my_list = [1, '2', 3.3]

To get a deeper understanding about data types in python you can wathc this video:

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Apr 4, 2021 in Java by Jake (7k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...