如何将由变量组成的列表连接到字符串中(python[3.6.2])

如何将由变量组成的列表连接到字符串中(python[3.6.2]),python,Python,这里有太多的代码要放,所以我将只显示问题发生的位置: date = [day,month,year,time] entrylist = [name,guess,date,email,phone] entry = ''.join(entrylist) print(entry) 对于“”加入(列表),它应该可以工作 >>> entrylist = ['name','guess','date','email','phone'] >>> entry = ''.joi

这里有太多的代码要放,所以我将只显示问题发生的位置:

date = [day,month,year,time]
entrylist = [name,guess,date,email,phone]
entry = ''.join(entrylist)
print(entry)
对于“”加入(列表),它应该可以工作

>>> entrylist = ['name','guess','date','email','phone']
>>> entry = ''.join(entrylist)
>>> print(entry)
nameguessdateemailphone
>>> entry = ' '.join(entrylist)
>>> print(entry)
name guess date email phone
>>>
如果需要加入列表列表,请使用以下格式

>>> a = [[1, 2, "sekar"],[3, "hello", "stack"],["overflow" ,4, "hi"]]
>>> ''.join(str(r) for v in a for r in v)
'12sekar3hellostackoverflow4hi'
>>> ' '.join(str(r) for v in a for r in v)
'1 2 sekar 3 hello stack overflow 4 hi'
>>>
如果您想将列表与变量组合在一起,请参见下文

>>> a = ['stack']
>>> b = ['over']
>>> c = ['flow']
>>> finallist = a + b + c
>>> ''.join(finallist)
'stackoverflow'
若列表中有数值,那个么在尝试连接之前必须将其转换为字符串,否则将抛出如下异常

>>> a = [1, 2, "sekar"]
>>> b = [3, "hello", "stack"]
>>> c = ["overflow" ,4, "hi"]
>>> finallist = a + b + c
>>> " ".join(x for x in finallist)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected str instance, int found
>>> " ".join(str(x) for x in finallist)
'1 2 sekar 3 hello stack overflow 4 hi'
>>>
>a=[1,2,“sekar”]
>>>b=[3,“你好”,“堆栈”]
>>>c=[“溢出”,4,“高”]
>>>finallist=a+b+c
>>>“”.join(finallist中x代表x)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:序列项0:应为str实例,找到int
>>>“”.join(在finallist中str(x)代表x)
'12 sekar 3 hello堆栈溢出4 hi'
>>>

你有一个列表,你需要在里面:
TypeError:sequence项1:预期的字符串,找到列表
错误消息说所有可能只是
entry=''。join(str(e)表示entrylist中的e)
将起作用。。。但是如果你不知道你的变量是什么,那就很难说了。。。请提供什么“问题正在发生”?如果没有这些信息,这个问题实际上无法回答。这是错误:entry=''。join(entrylist)TypeError:sequence item 0:expected str instance,tuple found您的代码在我的解释器中引发
TypeError