Basic Unpacking
Python allows you to 'unpack' sequences into individual variables in a single statement. This is most commonly used with tuples but works with any iterable.
Learning Objectives
Lesson Outline
Python allows you to 'unpack' sequences into individual variables in a single statement. This is most commonly used with tuples but works with any iterable.
Introduced in Python 3, the * operator allows you to capture 'everything else' into a list. This is useful when you only care about specific parts of a sequence.
Unpacking is incredibly powerful when iterating over a list of tuples or dictionaries.
Forget using a temp variable to swap two values. Python handles it elegantly using unpacking.