Alexey Korepanov
by Alexey Korepanov
~1 min read

Categories

Tags

TL;DR

a, *b, c = [1, 2, 3, 4, 5] # b gets [2, 3, 4]

In Python you can unpack array into multiple variables like this:

a, b = [1, 2]

What I didn’t know is that * operator can be used in the left part of the expression to produce a list:

a, *b, c = [1, 2, 3, 4, 5]

# b is now [2, 3, 4]

Available in Python 3.0 and higher.

You can find more details in PEP 3132.