quick question:
the following loop
but if I place the same loop into a function:
As far as I am understanding, the 'return' command interrupts the loop.
How do I make this function work the same way as the loop in the first code?
I am trying not to use any 'print' command inside the function.
the following loop
list_nums= [i for i in range(15)] for i in range(len(list_nums)): if list_nums[i]<9: print(list_nums[i])works as it should since all the numbers from 0 to 8 are printed,
but if I place the same loop into a function:
list_nums= [i for i in range(15)] def fn(): for i in range(len(list_nums)): if list_nums[i]<9: return(list_nums[i]) print(fn())Only the first number is printed.
As far as I am understanding, the 'return' command interrupts the loop.
How do I make this function work the same way as the loop in the first code?
I am trying not to use any 'print' command inside the function.