Review- Need Help please, me have question


#1



okay this doubt, have nothing to do with the Exam Statistics exams
I just want to know why this code below:


lst = [1,2,3,4,5]

def why_you(go):
    for i in go:
        i= i + 2
    return go
    print go
    
why_you(lst)    

DOESN'T print the returned lst "go" in this case "Lst"

but if i remove the "return go" line and let "print go" line like this:

lst = [1,2,3,4,5]

def why_you(go):
    for i in go:
        i= i + 2
    print go
    
why_you(lst)    

It will print the initial list (without the i= i+ 2 condition) that i need.

And what can i do ,so that when i call why_you(go) it will print the "remastered" list that i hope, without using the " print why_you(go)" of course. Thanks

#2

That code shouldn't work. After the return, all code within the function is considered "unreachable". You also will just return your list 5 times.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.