z412290894 发表于 2021-10-27 16:42:04

列表转换成字符串输出

本帖最后由 z412290894 于 2021-10-27 16:53 编辑

有一个列表:
plateresult = [(1, 'K'), (2, 'K'), (3, 'K'), (4, 'K'), (5, 'K'), (6, 'K')]
想在列表前面加几个文字,然后通过tkinter输出,要怎么转换?

期望输出:
单地形:(1, 'K'), (2, 'K'), (3, 'K'), (4, 'K'), (5, 'K'), (6, 'K')


def showdir(direct):
    root = Tk()
    root.geometry("300x100+500+550")
    root.title('Dorfromantik Start!')
    textlabel = Label(root, text=direct)
    textlabel.pack()
    Button(root, text='下一步', command=root.destroy).pack()
    mainloop()

suchocolate 发表于 2021-10-27 17:06:29

ls1 = [(1, 'K'), (2, 'K'), (3, 'K'), (4, 'K'), (5, 'K'), (6, 'K')]
result = ''
for i in ls1:
    result = f'{result}{i}{i}'
print(result)

z412290894 发表于 2021-10-27 17:16:10

suchocolate 发表于 2021-10-27 17:06


result = '单地形:'
for i in plateresult:
        result = f'{result}({i},{i})'
页: [1]
查看完整版本: 列表转换成字符串输出