Lists
One variable, many values. A list keeps items in order, like a playlist.
Code runs right here in your browser. Nothing to install.
Learn it
A list keeps many values in order inside one variable.
A list stores many values, in order, in one variable. Write the items inside square brackets, separated by commas: scores = [12, 45, 7]. A list can hold any types, even a mix.
len(scores) gives the number of items. print(scores) shows the whole list. An empty list is [].
Lists are mutable, which means you can change them after creating them: add items, remove items or replace them. You will do all of that in the next rooms.
squad = ["Nova", "Kai", "Mira"] scores = [120, 95, 140] print(squad) print("Squad size:", len(squad)) print("Top score:", max(scores)) print("Total:", sum(scores))
Try it yourself
+10 XPMake a list called games with your 4 favourite games (as strings). Print the list and then I listed 4 games using len().
Create a free account to start this lab
Sign in to write, run and check your code here. Your progress, XP and code are saved to your account. No card needed.
Capture the flag
+10 XPWhat does len([5, 8, 2, 9]) return?
Create a free account to start this lab
Sign in to answer the flag question. Your progress, XP and code are saved to your account. No card needed.
Weekly steps
+20 XPStore 7 daily step counts in a list called steps. Print the total with sum(), the best day with max(), and the average rounded to a whole number with round(). Labels: Total:, Best:, Average:.
Create a free account to start this lab
Sign in to do this homework and have it checked. Your progress, XP and code are saved to your account. No card needed.