ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
try:
    print(int('1__0'))
except ValueError:
    print('bad')
  1. A. 10
  2. B. bad
  3. C. 1
  4. D. 0

Correct answer: B. bad

Underscores in int() literals must sit between two digits, so a double underscore is invalid and raises ValueError. The except branch then prints 'bad'.

More Python Programming questions

Exams that ask this topic