ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
def check(v):
    assert v > 0, f"bad {v}"
    return v
try:
    check(-1)
except AssertionError as e:
    print("AE", e, end=" ")
except Exception:
    print("other", end=" ")
print(isinstance(AssertionError(), Exception))
  1. A. other True
  2. B. AE bad -1 True
  3. C. AE True
  4. D. AE bad -1 False

Correct answer: B. AE bad -1 True

A failing assert raises AssertionError with the message expression as its argument (when run without -O). AssertionError is an Exception subclass, but the first matching clause wins.

More Python Programming questions

Exams that ask this topic