Assign the result of a loop to a variable in Python

前端 未结 6 1817
予麋鹿
予麋鹿 2021-01-20 11:48

Consider a list I want to parse using a for :

friends = [\"Joe\", \"Zoe\", \"Brad\", \"Angelina\", \"Zuki\", \"Thandi\", \"Paris\"]
for i in fri         


        
6条回答
  •  暖寄归人
    2021-01-20 11:57

    If you want to join the values in friends into a comma-separated string, that would be

    s = ','.join(friends)
    

    If you want to include quotes around the names, maybe something like

    s = ','.join(['"{0}"'.format(x) for x in friends])
    

提交回复
热议问题