Difficulty: 7/10generator behavior, try/finally semantics, iterator returnCalling .return() on a generator will execute any pending finally block before terminating the generator, allowing cleanup operations to run.try/finally with .return()CopyScenario Questions0-2 years experience1If you have a generator that yields inside a try block with a finally that logs 'cleanup', what will be logged when the consumer calls gen.return()? 2Write a short generator using try/finally and show the output when you exit early with .return().2-5 years experience1You notice a file opened in a generator isn’t being closed when the iterator is aborted with .return(). Walk me through why the finally block isn’t executing as expected.Follow-up QuestionsWhat happens if the finally block itself contains a yield?How does .return() differ from throwing an exception into the generator?Can a finally block override the value passed to .return()? Why or why not?Suggest Improvement