Tuples

Tuples group multiple values into a single compound value. The values within a tuple can be of any type and do not have to be of the same type as each other.

let tuple = ("one", 2, "three")

// Values are read using index numbers starting at zero
print(tuple.0) // one
print(tuple.1) // 2
print(tuple.2) // three

Tuple with Multiple Types

let product = ("Laptop", 1500.99, true)
print(product)  // Output: ("Laptop", 1500.99, true)

Nested Tuples

Leave a Reply

Your email address will not be published. Required fields are marked *