Dinesh Beniwal
What is the difference between Python Arrays and lists?
By Dinesh Beniwal in Python on Jun 20 2019
  • Rohit Gupta
    Jul, 2019 15

    Both python arrays and list have many simillarities like they both are mutable, i.e. the content of both can be changed

    they differ with respect to the following
    Python arrays are used when we have to store homogenous type of data
    whereas List are used when we need to store hetrogenous kind of data

    Example

    1. #Array
    2. arr=array[(1,2,3),(1,2,3)]
    3. #list
    4. list=[1,2,3,4,5,6]

    one major differnce between the two can be seen by the following example

    1. from array import array
    2. if __name__=="__main__":
    3. arr=array([1,2,3,4,5])
    4. list=[1,2,3,4,5]
    5. #this will not result into an error
    6. print(arr/5)
    7. #this will result into an TypeError: array() argument 1 must be a unicode character, not list
    8. print(list/5)

    • 1
  • Laxmidhar Sahoo
    Dec, 2019 22

    Array : It is collection of variables represented by a common name with a common datatype.The variables are stored contineuosly.
    So it has element and index which is started from 0.
    example array(‘d’, [1.0, 2.0, 3.14])
    Here it is double type
    for more …..
    https://docs.python.org/3/library/array.html

    list with mixed datatypes

    my_list = [1, “Hello”, 3.4]

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS