Stuck with loops in python - only returning first value

后端 未结 5 1248
情话喂你
情话喂你 2020-12-02 01:16

I am a beginner in Python trying to make a function that will capitalize all of the values with an even index, and make lowercase all of the values with an odd index.

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 01:42

    You are returning from the function early. you need to collect the data you want to return in a variable.

    def func1(x):
    returnMe = {}
        for (a,b) in enumerate (x):
             if a%2 == 0:
                  returnMe += b.upper()
             else:
                  returnMe += b.lower()
    return returnMe
    
    
    func1('Testing Testing')
    
    >>>'T'
    

提交回复
热议问题