ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
try:
print(int('1__0'))
except ValueError:
print('bad')- A. 10
- B. bad
- C. 1
- 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
- What is printed? python print(float('1e400'), -float('1e400'), float('1e308') 10)
- What is printed? python print(int(1e23))
- What is printed? python print('x' 0 == '', 'Z' < 'a', '10' < '9', 'apple' < 'Apple')
- What is printed? python print(len('eu0301'), 'é' == 'eu0301')
- What is printed? python print(0b1010 & ~0b10, 0b1010 ^ 0b1111, 1 << 3 | 1, 6 & 3 == 2)
- What is printed? python print(1 << 100 >> 99) try: print(1 >> -1) except ValueError as e: print(e)