Answer the question
In order to leave comments, you need to log in
How to return return before the execution of the loop inside the function is completed?
There is a function.
In it, a loop with sleep () pauses
after the loop should be returned with a string for example.
How, when calling a function, to immediately get the return value without waiting for the end of the loop, and the loop would continue its work in the background?
Answer the question
In order to leave comments, you need to log in
Use a generator :
def f(x):
for x in range(x):
print('Hi!')
yield x
for i in f(10):
print(i)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question