Python Programming - Generators - Discussion
Discussion Forum : Generators - General Questions (Q.No. 84)
84.
What is the purpose of the
generator.send(value)
method when used with generators?
Answer: Option
Explanation:
generator.send(value)
sends a value into the generator, which is received as the result of the current yield
expression, and resumes the generator's execution.
def my_generator():
result = yield
print(f"Received value: {result}")
gen = my_generator()
next(gen) # Start the generator
gen.send(42) # Output: Received value: 42
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers