Printing tuple with string formatting in Python

前端 未结 14 2514
情话喂你
情话喂你 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条回答
  •  长情又很酷
    2020-11-28 04:01

    Note that the % syntax is obsolete. Use str.format, which is simpler and more readable:

    t = 1,2,3
    print 'This is a tuple {0}'.format(t)
    

提交回复
热议问题