倚天杖
它在一个迭代中解包多个项目。例如foo, bar = ['thing1', 'thing2']print(foo)print(bar)会输出thing1thing2所以如果我们说:packed_items = ['thing1', 'thing2']foo, bar = packed_itemsprint(foo)print(bar)我们会得到同样的结果。另一个需要了解的重要语法是*运算符。它可用于在打开包装时抓取任意数量的物品并将它们放入列表中。例如:packed_items = ['thing1', 'thing2', 'thing3', 'thing4', 'thing5']foo, *middle, bar = packed_itemsprint(foo, middle, bar)产量 thing1 ['thing2', 'thing3', 'thing4'] thing5然而foo, middle, *bar = packed_itemsprint(foo, middle, bar)会屈服 thing1 thing2 ['thing3', 'thing4', 'thing5']最后,注意*操作符可以返回一个空列表packed_items = ['thing1', 'thing2']foo, middle, *bar = packed_itemsprint(foo, middle, bar)产生thing1 thing2 []而不是因为没有足够的参数来解包而给你一个错误。