ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
try:
    print(int(''))
except ValueError:
    print('empty')
try:
    print(0.0 / 0)
except ZeroDivisionError:
    print('zero')
  1. A. zero empty
  2. B. empty zero
  3. C. empty nan
  4. D. empty inf

Correct answer: B. empty zero

int('') raises ValueError, and the first handler prints empty. Dividing a float by zero raises ZeroDivisionError rather than giving nan or inf, so the second handler prints zero.

More Python Programming questions

Exams that ask this topic