Meaning of using commas and underscores with Python assignment operator?

后端 未结 4 1928
我在风中等你
我在风中等你 2020-11-27 15:32

Reading through Peter Norvig\'s Solving Every Sudoku Puzzle essay, I\'ve encountered a few Python idioms that I\'ve never seen before.

I\'m aware that a function can

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 16:25

    _ is like any other variable name but usually it means "I don't care about this variable".

    The second question: it is "value unpacking". When a function returns a tuple, you can unpack its elements.

    >>> x=("v1", "v2")
    >>> a,b = x
    >>> print a,b
    v1 v2
    

提交回复
热议问题