ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
a = []
for i in range(20):
a.append(i)
print(len(a), a[-1], a.pop(), len(a))- A. 20 19 19 20
- B. 20 19 19 19
- C. 19 19 19 19
- D. 20 19 18 19
Correct answer: B. 20 19 19 19
Python evaluates print's arguments from left to right. The length is 20 and the last item is 19 before pop removes 19, so the final length is 19.
More Python Programming questions
- What is printed? python print(int('0012'), int('ff', 16), int('0b11', 0), int('1234'))
- What is printed? python print(-7 // 2, -7 % 2, 7 // -2, 7 % -2, divmod(-7, 2))
- What is printed? python print(round(0.5), round(1.5), round(2.5), round(-0.5), round(2.675, 2))
- What is printed? python s = 'aaaa' print(s.count('aa'), s.replace('aa', 'b'), 'a,,b'.split(','), ' x y '.split(' '))
- What is printed? python import itertools print([''.join(p) for p in itertools.permutations('abc', 2)][:4])
- What is printed? python import itertools print(len(list(itertools.combinationswithreplacement(range(5), 3))))