Python list Data Type

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']

By remaining on this website or using its content, you confirm that you have read and agree with the Terms of Use Agreement.

We are not liable for any damages resulting from using this website. Any information may be inaccurate or incomplete. See full Limitation of Liability.

Content may include affiliate links, which means we may earn commission if you buy on the linked website. See full Affiliate and Referral Disclosure.

We use cookies and similar technology to improve user experience and analyze traffic. See full Cookie Policy.

See also Privacy Policy on how we collect and handle user data.

© 2024 PyTut