What is the difference between a list and an array?

Lists are part of Python's syntax and hence do not need to be declared. However, performing functions such as dividing every entry in the collection by an integer by simply writing xs/2 is not possible with lists, only arrays. In Python, both lists and arrays can both be iterated over and indexed into, and can store any data type. Arrays are more compact and efficient and can perform more arithmetic functions.

LW

Related Python Mentoring answers

All answers ▸

[Student query] Why do we import libraries/modules such as Numpy and Matplotlib into Python?


Which four data types are used in Python? Can you give an example of each?


What are the main data structures that I can use in Python


Write a simple number guessing game, give the user 3 tries to guess a number between 1 and 10