Slices and Tuples
Slices and Tuples: Slicing Lists and Strings, Tuples and Unpacking.
Updated
- Slicing Lists and Strings (Apprentice): A slice such as stops[1:4] takes part of a list or a string, from the start index up to but not including the stop index, with an optional step, and because a string can't be changed in place, you build a changed copy from slices instead.
- Tuples and Unpacking (Apprentice): A tuple groups a few values that belong together, such as a city and its miles, and can't be changed once made, and unpacking gives each value its own name in one line, which is how a function returns two values and how two variables swap.