ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(len('a\nb'), len('a\\nb'), len(r'a\nb'), len('a\rb'))- A. 3 3 4 3
- B. 3 4 3 3
- C. 3 4 4 3
- D. 4 4 4 3
Correct answer: C. 3 4 4 3
'a\nb' has a real newline, so three characters. With double backslash the text holds a backslash and n, giving four. Raw strings keep the backslash, and \r is a carriage return, so 'a\rb' has three characters.
More Python Programming questions
- What is printed? python print(8 % -3, -8 % -3, 8 // -3, -8 // -3)
- What is printed? python t = str.maketrans('abc', 'xyz') print('aabbcc'.translate(t), len(t))
- What is printed? python import heapq h = [5, 1, 3, 1] heapq.heapify(h) print(h[0], heapq.heappop(h), heapq.nsmallest(2, [4, -1, 3])…
- What is printed? python from functools import reduce print(reduce(lambda a, b: a 10 + b, [1, 2, 3]), reduce(lambda a, b: a - b, [10, 2…
- What is printed? python print(sum(1 for c in 'a1b22c333' if c.isdigit()), ''.join(c for c in 'a1b22c333' if c.isalpha()), int(''.join(c…
- What is printed? python print(str(0.1 3), repr(0.1 3) == '0.30000000000000004', 0.1 3 == float(repr(0.1 3)))