A backpack with labeled pockets
Day 25 of 149
π Full deep-dive with code examples
The Backpack
Your backpack has pockets with labels:
- "water bottle" pocket β water bottle inside
- "pencils" pocket β pencils inside
- "lunch" pocket β sandwich inside
Objects are backpacks with labeled pockets!
In Code
backpack = {
"water_bottle": "blue bottle",
"pencils": 5,
"lunch": "sandwich"
}
To get lunch: backpack["lunch"] β "sandwich"
Arrays vs Objects
Array: Items by number
[apple, banana, cherry]
0 1 2
Object: Items by name
{fruit: apple, count: 3, color: red}
Use arrays for lists. Use objects when things have names!
Real Example
person = {
"name": "Alex",
"age": 25,
"city": "Sydney"
}
print(person["name"]) # Alex
In One Sentence
Objects store data with descriptive labels, like a backpack with named pockets for different items.
π Enjoying these? Follow for daily ELI5 explanations!
Making complex tech concepts simple, one day at a time.
Top comments (0)