ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(list(range(10, 0, -3)), list(range(-1, -10, -4)), len(range(0, 10, 3)), range(5)[-1])
- A. [10, 7, 4] [-1, -5, -9] 3 4
- B. [10, 7, 4, 1] [-1, -5, -9] 4 4
- C. [10, 7, 4, 1] [-1, -5] 4 5
- D. [10, 7, 4, 1] [-1, -5, -9, -13] 4 3
Correct answer: B. [10, 7, 4, 1] [-1, -5, -9] 4 4
range(10, 0, -3) stops before 0, giving 10, 7, 4, 1. The second range stops before -10, and len of range(0, 10, 3) is 4. Indexing a range with -1 gives its last element, 4.
More Python Programming questions
- What is printed? python print(len('anb'), len('anb'), len(r'anb'), len('arb'))
- 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…