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')- A. 7 7 7
- B. 0 7 leading zero
- C. 7 7 leading zero
- 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
- What is printed? python x = 1 / 3 print(x 3 == 1, 1 - 2 / 3 == 1 / 3, 0.1 + 0.2 - 0.3 == 0)
- What is printed? python s = 'ab' 2 + 'c' print(s.count('ab'), s.count('aba'), s.find('b', 2), s.rfind('ab'), s.index('c'))
- What is printed? python print('abc'.partition('x'), 'a=b=c'.partition('='), 'a=b=c'.rpartition('='))
- What is printed? python s = 'abcdefgh' print(s[::-2], s[1::3], s[-3:-6:-1], s[::-1][::2])
- What is printed? python print('%05.1f|%x|%o|%e' % (3.14159, 255, 8, 12345.678))
- What is printed? python print(f'{-5:+}', f'{5:+}', f'{3.0:g}', f'{1e6:g}', f'{1e-5:g}', f'{123456789.0:g}')