Assign the result of a loop to a variable in Python

前端 未结 6 1802
予麋鹿
予麋鹿 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 12:18

    Try this at the end of the loop:

    the_variable = the_variable + i
    

    However, if you are to do this, you should add a space to the end of every item in the dictionary, otherwise it will output:

    JoeZoeBradAngelinaZukiThandiParis
    

提交回复
热议问题