6.1 Intro to Lists

Intro to Lists

Most of you already know what lists are. You make lists all the time, like a bucket list or a grocery list. A list in Python is similar. When we make a list, we assign values to that list, which are numerically ordered. Lists can have any type of data inside them. For example:
my_list = [1, 2, "oh no", 4, 5.62]
View code on GitHub.

Making a List

As you saw in the previous example, you make a list just like you would a regular variable, except that you use the straight brackets and put the contents inside, separated by commas
another_list = ["data", "more data", "separated by commas"] # as you see, we have the variable name, another_list # we assign the data just as we would with an integer or string # the items in the list are separated by commas

Previous Chapter

Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.