Meaning of using commas and underscores with Python assignment operator?

后端 未结 4 1939
我在风中等你
我在风中等你 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:24

    You can use the trailing comma in a tuple like this:

    >>> (2,)*2
    (2, 2)
    
    >>> (2)*2
    4
    

提交回复
热议问题