Unpacking in Python
Unpacking in Python refers to assigning values in an iterable object to a tuple or list of variables for later use. We can perform unpacking by using an asterisk (
*) before the object we would like to unpack.
Unpacking a range object
To first create a range object of odd numbers between 1 and 10:
numbers = range(1,11,2)print(numbers)range(1, 11, 2)
To unpack the elements of the range object into a list:
numbers_list = [*numbers]print(numbers_list)[1, 3, 5, 7, 9]