Member-only story
What’s A Python List Exactly? | Straightforward Python

Python has a great built-in list type named “list”. List literals are written within square brackets [ ]. Lists work similarly to strings — use the len() function and square brackets [ ] to access data, with the first element at index 0. (See the official python.org list docs.)
They are used to store an ordered collection of items, which might be of different types but usually they aren’t. Commas separate the elements that are contained within a list and enclosed in square brackets. Just like in this example:
# These list elements are all of the same type
zoo = ['bear', 'lion', 'panda', 'zebra']
print(zoo)# But these list elements are not
biggerZoo = ['bear', 'lion', 'panda', 'zebra', ['chimpanzees', 'gorillas', 'orangutans', 'gibbons']]
print(biggerZoo)
You see that the second variable biggerZoo
is a list that is similar to the zoo
variable. However, you also see that biggerZoo
contains another list with different types of monkeys within.
Related Article: Dictionaries in Python? | Straightforward Python
List Methods
Here are some other common list methods.
- list.append(elem) — adds a single element to the end of the list. Common error: does not return the new list…