Variables, input & output
Every program starts with remembering things: names, scores, choices. Variables give those values a label in computer memory so you can reuse, combine, and manipulate them.
- Assign and re-assign values in memory using variables.
- Combine strings and values using concatenation.
- Implement the classic Band Name Generator logic combining city and pet name.
Variables bind human-readable identifiers to memory addresses.
In Python, variable assignment is dynamic: you do not need to declare types upfront like in Java (String name = '...') or C++. Python infers the type automatically at runtime.
A name for something worth remembering
A variable connects an identifier name to a value stored in RAM. In Python, assignment happens from right to left using a single equals sign.
Band Name Generator logic
Day 1 culminates in combining inputs into an exciting creative output: take the city you grew up in and your favourite pet to generate your band name!
Memory Trace: Variable Assignment & Band Name Generation
Follow how RAM allocates variable labels and joins strings in memory.
| Variable | Value in Memory | Data Type |
|---|---|---|
| city | "Bristol" | str (String) |
Text 'Bristol' is stored in memory address bound to label 'city'.
city = "Bristol"🔧 TypeError: String and Integer Concatenation
A student tried to build an intro message combining their name and age, but the program crashed with a TypeError.
Predict The Output (2 Questions)
Your lightbulb moment
The key takeaway
Variables label values in memory. Assignment updates what a label points to, and `+` concatenates strings.
Make it yours
Try changing the city to your hometown and the pet to your favourite animal to see your customized band name output!
Try editing the code in the playground above in Python, JavaScript, Java, or C++, and use the step-by-step Dry-Run Table to inspect how variables mutate in memory. If you get stuck, click the 🤖 AI Doubt Solver button on your screen for instant explanations!