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 DATA / CHAPTER 02 / Learn / LESSON 01
Chapter 2 — Data. In Foundations you already walked a list with for. Now we go deeper: length, index access, and appending a new item.
A list holds a sequence under one name. Square brackets [] mark the start and end. Items are separated by commas: weights = [70.0, 72.0, 74.0, 75.0]. Order matters — the first number is index 0; the last is the “newest” measurement in our example.
len(weights) returns the item count. That helps when the list grows: you do not count by hand. print(len(weights)) shows 4 for the lesson data.
Index 0 selects the first item, while -1 selects the last. append(value) adds a value at the end and changes the list:
weights.append(76.0)
print(weights[0])
print(weights[-1])These operations matter for logs that grow. for remains a familiar useful tool, but this chapter does not teach it again from scratch.
Mini example:
nums = [1.0, 2.0]
nums.append(3.0)
print(len(nums))
print(nums[0])
print(nums[-1])Common mistake: weights = 70.0 (one number instead of a list); or for without indentation; or using a comma as the decimal mark (70,0) — in Python it is a dot.
Today the log is the foundation: visible numbers, len, indexes, and append. Later classes will structure and transform the data.
We deepen familiar lists with length, indexes, and appending.
STREAM IDLE
›