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 ▸

How would you write a while loop to print all even numbers from 1-10?


Whats the output of "for i in "hello world": print(i)" and why/how is this achieved


What is the difference between a FOR loop and WHILE loop and how do I write them?


Manually implement a function that finds the smallest value in a list of integers and print it.