CODEX

Python 101: Working with Lists

Learn the basics of working with lists in Python

Artturi Jalli
CodeX
Published in
5 min readMar 18, 2021

--

Photo by AltumCode on Unsplash

In Python, a list is a sequence of elements that can be easily accessed, modified, and deleted.

numbers = [1, 2, 3]

Lists are useful as you can store objects in them.

For example, you could store a bunch of names into a list that represents a queue in a shopping mall.

Or you could store a list of player objects into a list and sort them by their height or skill level.

Anyway, today you are going to learn the basics of working with lists in Python without excess jargon.

How to Create a List

In Python, you can create a list by comma separating elements inside square brackets like this:

num_list = [1,2,3]word_list = ["cat", "car", "dog"]mixed_list = ["cat", 1, 2, "three"]

How to Count the Number of Elements in the List

To count the number of elements in a list, use the built-in len method.

For example:

numbers = [1,2,3]length = len(numbers)   # Counts the…

--

--

CodeX
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

No responses yet