Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PYTHON-将元组转换为字符串_Python_Python 3.x_List_Tuples_Typeerror - Fatal编程技术网

PYTHON-将元组转换为字符串

PYTHON-将元组转换为字符串,python,python-3.x,list,tuples,typeerror,Python,Python 3.x,List,Tuples,Typeerror,我有这个[(5,)],我相信它是列表中的一个元组,我只想得到值5 我尝试了“”。join(variable)但引发了此错误:TypeError:sequence item 0:expected str instance,tuple found 我认为索引方法也不起作用,因为值5可以是任何正整数(即,有时需要返回多个数字) 提前感谢:)使用var[0][0]获取您的号码,以防var是您的变量。variable[0][0]将返回号码,str(variable[0][0])`将其转换为字符串。 tup

我有这个
[(5,)]
,我相信它是列表中的一个元组,我只想得到值5

我尝试了
“”。join(variable)
但引发了此错误:
TypeError:sequence item 0:expected str instance,tuple found

我认为索引方法也不起作用,因为值
5
可以是任何正整数(即,有时需要返回多个数字)


提前感谢:)

使用
var[0][0]
获取您的号码,以防
var
是您的变量。

variable[0][0]
将返回号码,str(variable[0][0])`将其转换为字符串。
tuple_list = [(5,)]

for item in tuple_list:
    print(item[0]) # --> 5