Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON FOUNDATIONS / CHAPTER 01 / Learn / LESSON 06
Fifth class. One weight is a snapshot. Health is a stream — a series of measurements over time.
A list holds several values under one name: history = [70, 72, 74, 75]. Indexes start at 0, but today we will not dig into indexes — we will walk the whole list.
The loop for value in history: means: “for each item, call it value and run the body”. Inside you usually print(value) or do other work. Without a loop you would write print four times by hand — with a loop the code grows with the data.
Mini example:
nums = [10, 20, 30]
for n in nums:
print(n)You can mix constants and variables: [70, 72, 74, weight] — the last item is the current weight from earlier lessons.
Common mistake: for without indentation; or history = 70 (a number instead of a list); or printing once outside the for.
Lists store a sequence. for value in history: repeats the body for each item.
STREAM IDLE
›