Printing tuple with string formatting in Python

前端 未结 14 2498
情话喂你
情话喂你 2020-11-28 03:19

So, i have this problem. I got tuple (1,2,3) which i should print with string formatting. eg.

tup = (1,2,3)
print \"this is a tuple %something\" % (tup)
         


        
14条回答
  •  旧时难觅i
    2020-11-28 04:06

    >>> thetuple = (1, 2, 3)
    >>> print "this is a tuple: %s" % (thetuple,)
    this is a tuple: (1, 2, 3)
    

    Making a singleton tuple with the tuple of interest as the only item, i.e. the (thetuple,) part, is the key bit here.

提交回复
热议问题