Skip to main content

Command Palette

Search for a command to run...

πŸš‚ Arrays Explained Like You're 5

Published
β€’1 min read
S

Building AI systems and writing about how they actually work. Master of AI @ University of Technology Sydney. Previously B.Tech CS with focus on IoT. I believe the best way to learn is to explain. That's why I'm documenting tech concepts with simple analogies (@sreekarreddy.com). AWS Certified β€’ Azure AI Certified β€’ Neo4j Professional β€’ Google Data Analytics When not coding: exploring Sydney, working on side projects, and teaching tech to anyone who'll listen.

Train compartments in a row

Day 24 of 149

πŸ‘‰ Full deep-dive with code examples


The Train

Imagine a train with numbered compartments:

πŸš‚ [Car 0] [Car 1] [Car 2] [Car 3] [Car 4]

Each car has a number (starting from 0!) and can hold one thing.

Arrays are trains for your data!


In Code

fruits = ["apple", "banana", "cherry", "date"]
Index:    0         1          2        3
       ["apple", "banana", "cherry", "date"]

To get banana: fruits[1] (index 1, the second item)


Why Start at 0?

Tradition from early computers! Just remember:

  • First item = index 0
  • Second item = index 1
  • Third item = index 2

What Can You Do?

ActionCodeResult
Get itemfruits[2]"cherry"
Change itemfruits[0] = "apricot"Updates first item
Add itemfruits.append("elderberry")Adds to end
Countlen(fruits)5

In One Sentence

Arrays store multiple items in a numbered list, like numbered train compartments in a row.


πŸ”— Enjoying these? Follow for daily ELI5 explanations!

Making complex tech concepts simple, one day at a time.

More from this blog

esreekarreddy

132 posts