python - Python:如何打印不带引号和方括号的列表
问题描述
我正在尝试以, , .list
格式打印此 pythonvalue1
value1
value3
但我得到的是这样的:
['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]
解决方案
在 上使用join
函数str
:
>>> mylist = ['value1', 'value2', 'value3']
>>> print(mylist)
['value1', 'value2', 'value3']
>>> print(', '.join(mylist))
value1, value2, value3
推荐阅读
- r - 通向地图的管道最终给出了不正确长度的列表
- javascript - AngularJS + 提供者 + Webpack
- python - Spyder IDE:Mac 上没有名为 pip 的模块
- node.js - 无法使用硒定位元素
- java - java.lang.ExceptionInInitializerError 不会消失
- angular - 使用 Power REST API 时,有没有办法从报告中过滤掉“隐藏”页面 - 获取组中的页面
- r - 从 ggraph 图中的动态布局中删除孤立节点
- python - 在 python 中使用连接的 wifi 检查互联网连接可用性
- python - 无服务器 YAML stepFunctions:TypeError:无法读取未定义的属性“配置文件”
- javascript - VueJS:以编程方式将组件附加到 $ref 元素