Asterisks outside of function calls

后端 未结 1 1602
日久生厌
日久生厌 2020-12-07 02:33

I\'m venturing into python and I had a question regarding asterisks. I know that they are used for arguments in function calls but I have seen snippets of code using them ou

相关标签:
1条回答
  • 2020-12-07 03:34

    Python 3 added extended tuple unpacking with support for one wildcard, see PEP 3132:

    *start, tail = ...
    head, *middle, tail =  ...
    

    See the assignment statements reference documentation:

    If the target list contains one target prefixed with an asterisk, called a “starred” target: The object must be a sequence with at least as many items as there are targets in the target list, minus one. The first items of the sequence are assigned, from left to right, to the targets before the starred target. The final items of the sequence are assigned to the targets after the starred target. A list of the remaining items in the sequence is then assigned to the starred target (the list can be empty).

    Use of an asterix in the lef-hand side (target list) of an assignment is a syntax error in Python 2.

    0 讨论(0)
提交回复
热议问题