Printing tuple with string formatting in Python

前端 未结 14 2421
情话喂你
情话喂你 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:02

    Talk is cheap, show you the code:

    >>> tup = (10, 20, 30)
    >>> i = 50
    >>> print '%d      %s'%(i,tup)
    50  (10, 20, 30)
    >>> print '%s'%(tup,)
    (10, 20, 30)
    >>> 
    

提交回复
热议问题