Python:从元组转换为字符串? [英] Python: Converting from Tuple to String?
本文介绍了Python:从元组转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有字符串:
s = "元组:"
和元组(存储在名为 tup 的变量中):
(2, a, 5)
我试图让我的字符串包含值Tuple: (2, a, 5)".我注意到你不能只是连接它们.有谁知道最直接的方法来做到这一点?谢谢.
解决方案
这也有效:
<预><代码>>>>s = "元组:" + str(tup)>>>秒元组:(2,'a',5)"let's say that I have string:
s = "Tuple: "
and Tuple (stored in a variable named tup):
(2, a, 5)
I'm trying to get my string to contain the value "Tuple: (2, a, 5)". I noticed that you can't just concatenate them. Does anyone know the most straightforward way to do this? Thanks.
解决方案
This also works:
>>> s = "Tuple: " + str(tup)
>>> s
"Tuple: (2, 'a', 5)"
这篇关于Python:从元组转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文