首页 > 解决方案 > Python:如何打印不带引号和方括号的列表

问题描述

我正在尝试以, , .list格式打印此 pythonvalue1value1value3

但我得到的是这样的:

['value1', 'value2', 'value3']

所以我想摆脱'and []

这是我尝试过的,但它现在打印的结果没有括号

tagList = []
count = 0
for i in range(20):
    try:
        if not response['TagList'][i]['Key']:
            print("Tags not found")
        else:
            if str(response['TagList'][i]['Key']) == "t_AppID":
                pass
            tagList.append(str(response['TagList'][i]['Key']))
    except:
        pass

return str(tagList)[1:-1]

标签: python

解决方案


在 上使用join函数str

>>> mylist = ['value1', 'value2', 'value3']
>>> print(mylist)
['value1', 'value2', 'value3']
>>> print(', '.join(mylist))
value1, value2, value3

推荐阅读