How to create a tuple with only one element

前端 未结 3 1326
执笔经年
执笔经年 2020-11-22 00:43

In the below example I would expect all the elements to be tuples, why is a tuple converted to a string when it only contains a single string?

>>> a         


        
3条回答
  •  遇见更好的自我
    2020-11-22 01:36

    ('a') is not a tuple, but just a string.

    You need to add an extra comma at the end to make python take them as tuple: -

    >>> a = [('a',), ('b',), ('c', 'd')]
    >>> a
    [('a',), ('b',), ('c', 'd')]
    >>> 
    

提交回复
热议问题