Lesson 1 of 21 · 48 min · UG / professional
Tuples — a shape that should not grow
Gate latitude/longitude is two numbers, not a tray that sprouted a note. On a laptop that stiffness is a tuple. Here it is a two-field record with the same policy.
Persistent store
Files and tables remember after the program stops.
You will be able to
- ✓ Treat a GPS pair or a roll-and-name pair as a record that must not grow a mystery slot
- ✓ Model the same stiffness as a two-field dict in this sandbox (a tuple on a laptop)
- ✓ Keep every extra note as a named field, never an anonymous third item
A pair that should stay a pair
Gate 2’s latitude and longitude are two numbers the survey team agreed on. They should not sprout a third mystery value because someone appended a sticky-note. On a laptop that stiffness is a tuple: you build a new pair if the reading is revised; you do not append. This sandbox does not run tuple syntax, so the honest twin is a two-field dict — lat and lon labelled, no surprise column.
A hostel line (roll, name) is the same contract. If you need a remark, it is a third named field, not an extra anonymous slot. Fixed shape is how the gate firmware and the attendance script agree what “a student at a turnstile” is. A list that is sometimes two items and sometimes five is not a pair; it is a bug waiting for the first inspection.
Laptop: a real tuple stays a pair
gate = (18, 73) print(gate[0], gate[1]) # gate.append(0) # AttributeError — that is the point revised = (18, 74) print(revised)
Named fields, not a tray that grew
UPI settlement on campus is often a txn id plus paise. Those two parts travel together. If accounts later want a GSTIN, you add a key, you do not shove a string onto the end of a nameless sequence and hope the next intern guesses the order.
When you need many pairs — every gate on the ring road — you keep a list of those records. Each record still has the same keys. That is a table of pairs, not one giant list of mixed leftovers.
Words that matter
- Tuple
- An immutable sequence on a laptop — a pair or row that should not grow.
- Fixed shape
- Every record of this kind has the same named parts.
- Record
- A labelled pair or row; a dict here, a tuple or named fields on a laptop.
Common mistakes
Avoid: A list of GPS points that sometimes has 2 items and sometimes 5.
Do this: A two-field record (tuple on a laptop, dict here) or a named field for every extra.
Run it step by step
Each box is a real program. Press Run, change a number, Run again — the output must follow your code.
1. Step 1 — a pair as two named fields
lat and lon stay labelled. There is no anonymous third slot.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
2. Step 2 — many pairs, same keys
Two hostel lines. First roll is 12. Count of rows is 2.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
Example program — A UPI pair plus an optional named remark
Remark is a key, not a third nameless slot.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
Your turn — Read the second roll
rows has rolls 12 then 7. Print the second roll so 7 appears.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
Self-assessment
Check your understanding before you mark the lesson complete.
Progress is stored in a browser cookie on this device.