I was researching about python codegolf and saw someone use the unpacking operator in a strange way:
*s,='abcde'
I know that the unpacking operator basically iterates over a sequence. So I know that
s=[*'abcde']
will "unpack" the abcde
string and save ['a', 'b', 'c', 'd', 'e']
in variable s
.
Can someone explain as thoroughly as possible how does the
*s,='abcde'
statement work? I know it does the same thing as s=[*'abcde']
but it accomplishes it in a different way. Why is the unpacking iterator on the variable, instead of the string? Why is there a comma right after the variable name?