I am trying to make sense of starred expressions in python. When I use it in python functions, it allows to call functions with different number of arguments:
def my_sum(*args):
results = 0
for x in args:
results += x
return results
print(my_sum(1,2,3))
>>6
print(my_sum(1,2,3,4,5,6,7))]
>>28
However when I use it in an assignment, it works like this:
a, b, *c, d = [1,2,3,4,5,6,7,8,9,10]
print(a,b,c,d)
>>1 2 [3, 4, 5, 6, 7, 8, 9] 10
*a, b, *c, d = [1,2,3,4,5,6,7,8,9,10]
print(a,b,c,d)
*a, b, *c, d = [1,2,3,4,5,6,7,8,9,10]
^
SyntaxError: multiple starred expressions in assignment
Can someone explain to me what is happening behind this assignment that doesn't allow multiple starred expressions?