① problem: If there is a tuple or sequence containing n multiple elements, now you want to break it down into n separate variables.
1 L = (4, 5)2 x, y = l
View Code
② Advanced article:
data = ['sb' ' big hammer ', (2018, 6, 2 = dataa='sb'b=' big hammer ' C=51Date= (2018, 6, 2)
③
data = ['sb' ' big hammer ', (2018, 6, 2 == 2018= 6= 2
View Code
So then the question comes, this is to know the list of how much of the situation to achieve, if the unknown? that will use the * expression to decompose the iterated object.
* syntax is useful when iterating over a tuple sequence of an edge length, with an example:
Records = [ ('Foo', 1, 2), ('Bar','Hi'), ('Foo', 3, 4),]defDo_foo (x, y):Print('Foo', x, y)defDo_bar (s):Print('Bar', s) forTag, *argsinchRecords:ifTag = ='Foo': Do_foo (*args)elifTag = ='Bar': Do_bar (*args)
View Code
Data structures and algorithms-decomposing sequences into separate variables