Avinash Kumar Avinash Kumar - 1 year ago 78
Python Question

Return value in Python for Loop

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

def asd():
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 Source

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

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