What is a List in Python?
A list is an ordered, mutable collection of items. The “items” within the list may be of different of data types. The items may also be other collection data types like dictionaries, tuples, arrays or even another list. Python lists are a very powerful tool used widely.
Lists are great, but not suitable for every task. There are other data structures out there like arrays, tuples and dictionaries which may be more suitable for certain tasks. First scope out your problem and then decided which data type fits the best. There are also special data structures like “deque” which can offer some performance benefits over lists.
Python Lists Syntax
newlist = ["Python","Java","C++","Ruby"]The items within the list must be enclosed within square brackets, and each item must be separated by a comma. Unlike arrays, Lists can store any type of data type as well as store variables of different datatypes at the same time.
The double quotes are not part of the syntax of the list. They are only necessery if the item is a string.
List Indexing
You can access the contents of a list by using it’s index. A list is an ordered collection, so the values can be called in the order in which they were placed inside.
