Python list
is a mutable ordered collection of items:
>>> symbols = ['AAPL', 'MSFT', 'NVDA'] >>> type(symbols) <class 'list'>
The items can be of different types:
>>> various_things = ['AAPL', 123, False, None, 'NVDA'] >>> type(various_things) <class 'list'>
There can be duplicates (this is main difference from set
):
>>> with_duplicates = ['AAPL', 'MSFT', 'AAPL'] >>> type(with_duplicates) <class 'list'>
Main difference between list
and tuple
is that list
is mutable = can be modified later:
>>> symbols = ['AAPL', 'MSFT', 'NVDA'] >>> symbols ['AAPL', 'MSFT', 'NVDA'] >>> symbols[1] = 'XOM' >>> symbols ['AAPL', 'XOM', 'NVDA']