CODEX
Python 101: Working with Lists
Learn the basics of working with lists in Python
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…