Question OOP-CTOR-0045
MediumWhat is the output of this code?
class R:
def __init__(self, n):
self.n = n
print("open", n, end="; ")
def __enter__(self):
return self
def __exit__(self, *a):
print("close", self.n, end="; ")
with R(1) as r:
print("use", r.n, end="; ")
- A.
use 1; open 1; close 1;
- B.
open 1; use 1;
- C.
Sign up free to see the answer and a step-by-step explanation.