Assign the result of a loop to a variable in Python

前端 未结 6 1814
予麋鹿
予麋鹿 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:17

    var = ''
    friends = ["Joe", "Zoe", "Brad", "Angelina", "Zuki", "Thandi", "Paris"]
    for i in friends:
        var=i 
    

    if list and loop are in function then declare var as global

    global var
    

    in starting of function

提交回复
热议问题