Are there any uses of the empty tuple in Python?

前端 未结 3 1853
南旧
南旧 2020-12-18 18:25

Is there any other purpose (besides being there because it needs to be) the empty tuple may have? Or: what would you use the empty tuple for? If anything. I just can\'t find

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 19:05

    You might want to store the arguments to a function as a tuple, without knowing the structure of the function in advance. If it happens that the function you need to store the parameters for takes no parameters, you will need to store an empty tuple.

    This is just one among many examples of why it's generally better not to question the existence of edge cases, just because we can't think of a use for them. The need to support the edge case invariably crops up before long.

提交回复
热议问题