Thursday, June 28, 2012

Python - unpack arguments from list with star operator


We can use *-operator (star operator) to unpack the arguments out of a list or tuple. Here is an example with python built in range() function :
>>> mylist = [3, 10]
>>> mylist
[3, 10]
>>> range(mylist[0], mylist[1])
[3, 4, 5, 6, 7, 8, 9]
>>> range(*mylist)
[3, 4, 5, 6, 7, 8, 9]
>>> 

0 Comments: