Interviews - C# Corner

Dinesh Beniwal
What is the difference between Python Arrays and lists?
By Dinesh Beniwal in Python onJun 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


    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)

    • 0

Most Popular Companies

Most Popular Job Functions