Python add item to the tuple

后端 未结 7 2083
暗喜
暗喜 2020-12-22 16:11

I have some object.ID-s which I try to store in the user session as tuple. When I add first one it works but tuple looks like (u\'2\',) but when I try to add ne

相关标签:
7条回答
  • 2020-12-22 17:14

    Tuple can only allow adding tuple to it. The best way to do it is:

    mytuple =(u'2',)
    mytuple +=(new.id,)
    

    I tried the same scenario with the below data it all seems to be working fine.

    >>> mytuple = (u'2',)
    >>> mytuple += ('example text',)
    >>> print mytuple
    (u'2','example text')
    
    0 讨论(0)
提交回复
热议问题