Member-only story

What’s A Python List Exactly? | Straightforward Python

Developers Group
3 min readApr 29, 2021

--

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…

--

--

Developers Group
Developers Group

Written by Developers Group

A Developer is responsible for coding, designing, deploying, and debugging development projects, typically on the server-side (or back-end).

No responses yet

Write a response