What is the output of the following code? from contextlib import contextmanager @contextmanager def managed(): print(‘enter’) try: yield 42 finally: print(‘exit’) with managed() as v: print(v)
Python ProfessionalHard
Python Professional — Hard
What is the output of the following code? from contextlib import contextmanager @contextmanager def managed(): print(‘enter’) try: yield 42 finally: print(‘exit’) with managed() as v: print(v)
Explanation
The output of the code is "enter 42 exit." This is because the context manager function "managed" prints "enter" before yielding the value 42, and then prints "exit" after the yield statement.