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

后端 未结 7 2193
时光说笑
时光说笑 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:21

    I was somewhat confused about the application of the comma, as you also apply a comma to make a list instead of tuple, but with a different variable assignment.

    Hereby, a simple example that I made of how to create a tuple or a list.

    abc = 1,2,3 # prints a tuple: (1, 2, 3)
    *abc, = 1,2,3 # prints a list: [1, 2, 3]
    
    0 讨论(0)
提交回复
热议问题