ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(int('0_7'), int('07'))
try:
    print(int('07', 0))
except ValueError:
    print('leading zero')
  1. A. 7 7 7
  2. B. 0 7 leading zero
  3. C. 7 7 leading zero
  4. D. 7 7 0

Correct answer: C. 7 7 leading zero

With an explicit base of 10, int() accepts leading zeros and underscores between digits. Base 0 uses the literal rules of Python code, where a leading zero before a nonzero digit is not allowed, so int('07', 0) raises ValueError.

More Python Programming questions

Exams that ask this topic