Why does adding a trailing comma after a variable name make it a tuple?

后端 未结 7 2287
时光说笑
时光说笑 2020-11-22 15:43

I want to know that why adding a trailing comma after a variable name (in this case a string) makes it a tuple. i.e.

>>> abc = \'mystr         


        
7条回答
  •  孤独总比滥情好
    2020-11-22 16:19

    It is the commas, not the parentheses, which are significant. The Python tutorial says:

    A tuple consists of a number of values separated by commas

    Parentheses are used for disambiguation in other places where commas are used, for example, enabling you to nest or enter a tuple as part of an argument list.

    See the Python Tutorial section on Tuples and Sequences

提交回复
热议问题