Arrays and Lists

► Understanding Arrays and Lists

Lists (also called arrays in other languages) are ordered collections that can store multiple items in a single variable. Lists are mutable, meaning you can modify their contents after creation. They’re one of the most versatile and commonly used data structures in programming.

► Real-World Analogy

Think of a list like a shopping cart:
» You can add items to your cart (append)
» You can remove items you don’t want (remove)
» Items are in a specific order (indexed)
» You can check what’s at position 3 (access by index)
» You can count how many items are in the cart (length)
» You can rearrange items or empty the cart completely

► Key Concepts

✓ Ordered collection: Items maintain their position
✓ Mutable: Can be changed after creation
✓ Indexed: Access items using position (starting from 0)
✓ Dynamic size: Can grow or shrink as needed
✓ Mixed types: Can store different data types

■ Code Examples