Lists are ordered, zero-indexed, and can hold values of mixed types.
Literal Syntax
let numbers = [1, 2, 3, 4, 5]
let mixed = [42, "hello", true, 192.168.1.1]
let empty = []
Indexing
let first = numbers[0] // 1
let last = numbers[-1] // 5 (negative indexing from end)
Out-of-bounds access raises a Runtime Error:
numbers[99]
// ❌ Runtime Error: List index 99 is out of range (length 5).
// 💡 Hint: Valid indices are 0 to 4.
Index Assignment
let fruits = ["apple", "banana", "cherry"]
fruits[1] = "blueberry"
print(fruits) // [apple, blueberry, cherry]
Iterating
for item in numbers {
print(item)
}
List Methods
See §14 List Methods for the full method reference.