![](/img/trans.png)
[英]Python print a list of strings horizontally without quotations or brackets
[英]Python: How to print a list without quotations and square brackets
我正在嘗試以value1
, value1
, value3
格式打印此 python list
。
但我得到的是這樣的:
['value1', 'value2', 'value3']
所以我想擺脫'
和[]
。
這是我嘗試過的,但它現在只打印沒有括號的結果:
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]
在str
上使用join
函數:
>>> mylist = ['value1', 'value2', 'value3']
>>> print(mylist)
['value1', 'value2', 'value3']
>>> print(', '.join(mylist))
value1, value2, value3
要將列表元素作為字符串返回,您可以使用以下內容:
def as_string(values):
return ', '.join(values)
print(as_string(['a', 'b', 'c'])
a, b, c
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.