Python: Converting from Tuple to String?

前端 未结 3 1786
情话喂你
情话喂你 2020-12-19 02:42

let\'s say that I have string:

    s = \"Tuple: \"

and Tuple (stored in a variable named tup):

    (2, a, 5)
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-19 02:46

    Try joining the tuple. We need to use map(str, tup) as some of your values are integers, and join only accepts strings.

    s += "(" + ', '.join(map(str,tup)) + ")"
    

提交回复
热议问题