@@ -222,12 +222,20 @@ This will pack all the values into a `list`/`tuple`.
222222>> > combined_fruits
223223(" apple" , " banana" , " cherry" , " orange" , " kiwi" , " melon" , " mango" )
224224
225- # If the * operator is used on the left side of "=" the result is a list
225+ # If the * operator is used on the left side of "=" the result is a list.
226+ # Note the trailing comma.
226227>> > * combined_fruits_too, = * fruits, * more_fruits
227228>> > combined_fruits_too
228229[' apple' , ' banana' , ' cherry' , ' orange' , ' kiwi' , ' melon' , ' mango' ]
230+
231+ # A list literal can be used instead, but might not be as readable.
232+ >> > [* combined_fruits_too] = * fruits, * more_fruits
233+ >> > combined_fruits_too
234+ [' apple' , ' banana' , ' cherry' , ' orange' , ' kiwi' , ' melon' , ' mango' ]
229235```
230236
237+ For more details on the use of ` * ` and ` ** ` , check out [ PEP 3132] [ pep-3132 ] and [ PEP 448] [ pep-448 ] .
238+
231239### Packing a dictionary with ` ** `
232240
233241Packing a dictionary is done by using the ` ** ` operator.
@@ -370,6 +378,8 @@ Since `zip()` takes multiple iterables and returns a `list` of `tuples` with the
370378[ items ] : https://docs.python.org/3/library/stdtypes.html#dict.items
371379[ multiple assignment ] : https://www.geeksforgeeks.org/assigning-multiple-variables-in-one-line-in-python/
372380[ packing and unpacking ] : https://www.geeksforgeeks.org/packing-and-unpacking-arguments-in-python/
381+ [ pep-448 ] : https://peps.python.org/pep-0448/
382+ [ pep-3132 ] : https://peps.python.org/pep-3132/
373383[ sorting algorithms ] : https://realpython.com/sorting-algorithms-python/
374384[ unpacking ] : https://www.geeksforgeeks.org/unpacking-arguments-in-python/?ref=rp
375385[ view-objects ] : https://docs.python.org/3/library/stdtypes.html#dict-views
0 commit comments