ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(' x\t'.strip() == 'x', 'a\tb'.expandtabs(4), len('a\tb'.expandtabs(4)), 'ab\r\ncd'.splitlines())- A. True a b 3 ['ab', 'cd']
- B. True a b 4 ['ab\r\ncd']
- C. True a b 5 ['ab', 'cd']
- D. False a b 5 ['ab', 'cd']
Correct answer: C. True a b 5 ['ab', 'cd']
strip() removes the tab, and expandtabs(4) pads the tab to the next column multiple of 4, which here is three spaces. splitlines() treats \r\n as one line break, so it returns two strings.
More Python Programming questions
- What is printed? python print('²'.isdigit(), '²'.isdecimal(), '²'.isnumeric(), '٥'.isdecimal())
- What is printed? python print(len('é'.encode('utf-8')), len('é'.encode('utf-16-le')), len('a€'.encode()), b'xc3xa9'.decode())
- What is printed? python print(f"{12:>{5}}|{3.14159:.{2}f}|{'ab':^6}")
- What is printed? python x = 12 print(x & -x, x ^ (x - 1), (x & (x - 1)) == 0, -x & x == x & -x)
- What is printed? python print((-5).tobytes(2, 'big', signed=True).hex(), int.frombytes(b'xffxfb', 'big', signed=True)…
- What is printed? python import math print(math.fsum([0.1] 10) == 1.0, sum([0.1] 10) == 1.0, math.isqrt(10 30 - 1))