-2
The command return
completes the function, so when you do the loop
and puts the return
within it, it returns only the first element of loop
and then the function ends, the correct one is returns the set of values.
def returnAllValues(listOfValues):
return listOfValues
def returnFirstValue(listOfValues):
for value in listOfValues:
return value
x = [1, 2, 3]
print(returnAllValues(x))
print(returnFirstValue(x))
Output:
[1, 2, 3]
1
Do not use images when posting your question. Always post code.
– JhowBhz