Post

@Python_Dv Answer: C=10
def func(elements):
Defines a function that takes a list.
for x in elements:
Starts looping through the list. First value is 10.
return x
Returns the first element immediately and exits the function.
print(func([10, 20]))
Function stops at 10, so output is 10.
English

@Python_Dv Answer: A. 10
The return x statement is inside the for loop, meaning the function exits immediately during the first iteration when x is assigned the value 10. The loop terminates, and the value 10 is returned
English

@Python_Dv func() returns the first element 10 since the loop returns only x
English

@Python_Dv Answer: A
Solution: Here the main trick is that...
`return` takes you out of the function.
Breaks out of every loop, conditional, whatever.
Straight back to where the function was called from.
Here func is called in the argument to print.
Inside func there is a loop over
+
English

@Python_Dv C
The return will break the loop, so it'll only get elements[0]... anyway, why don't we just use elements[0] directly?
English









