Unpacking a list in Python
Unpacking of list in Python :
In Python, there is a feature of the List that assigns the right-hand side values to the left-hand side. In another way, it is called unpacking of a List in Python. In packing, we put values into a new list while in unpacking we extract those values into a single variable.
- ( a, b, c ) = list_name.
A list is a data structure in Python that is a mutable, or changeable, ordered sequence of elements. Each element or value that is inside of a list is called an item.
Code #1 :
- Sometimes there are n numbers of input in one line, which contains one or more variable at any end and an array of number or string. Here we can use this property (Unpacking a List in Python) which simplifies our work.
- Python uses a special syntax to pass optional arguments (*args) for List unpacking. This means that there can be any numbers of arguments in place of (*args). We can use any variable name in place of “*args”.
Code #2 :
The given List: [4, 5, 4, 2, 7, 7]
The size of array: 4
array: [5, 4, 2, 7]
Max of the array: 7