ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
s = '42' print(s * 2 + '!' if s.isdigit() else '', int(s) * 2, s.zfill(4) + '|' + s.rjust(4, '0') + '|' + s.ljust(4, '0'))
- A. 4242! 84 0042|0042|0042
- B. 42!! 84 0042|0042|4200
- C. 4242! 84 0042|0042|4200
- D. 4242! 42 0042|0042|4200
Correct answer: C. 4242! 84 0042|0042|4200
The conditional expression applies to the first argument, so s * 2 + '!' is printed. zfill, rjust and ljust pad to four characters with zeros, using the left or right side as each method specifies.
More Python Programming questions
- What is printed? python print(sum(map(int, '123456789')) == 45, sum(map(int, str(99))), 99 % 9)
- What is printed? python print('a' 3 < 'b', 'a' 3 < 'aa', 'aaa' > 'aab', 'aa' + 'b' > 'aab')
- What is printed? python x = 5 print(x // 2 2 == x, x / 2 2 == x, 5 / 2 == 2.5, 5 // 2.0 == 2)
- What is printed? python print(bytes('é', 'utf-8'), 'é'.encode('latin-1'), len('é'.encode('latin-1')) == len('é'.encode('utf-8')))
- What is printed? python print(round(-0.5), round(0.5), round(1.5), round(-1.5), round(2.5))
- What is printed? python x = [3, 1, 2] print(sorted(x, reverse=True)[:2], x[::-1][1:], list(reversed(sorted(x))))