Avinash Kumar Avinash Kumar - 1 month ago 9
Python Question

Return value in Python for Loop

Hi want to return value after for loop. My code is -

def asd():
data.append("a")
data.append("b")
for i in range(0,2):
value = data[i]
return value


I am expecting to return both a and b when calling the function but it is returning only b. Is there any other method. Thanks in advance

Answer

Unless you have a very pressing reason for doing things this way, this example can be simplified to

def asd():
    return 'a', 'b'