ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print(sum([True, True, False]), True * 3, 'ab' * True, [0] * True)
- A. 2 3 abab [0]
- B. 2 3 ab [0]
- C. 2 3 ab [0, 0]
- D. 1 3 ab [0]
Correct answer: B. 2 3 ab [0]
bool is a subclass of int, so True counts as 1 in sums, products and repetition. 'ab' * True repeats the string once and [0] * True gives one element.
More Python Programming questions
- What is printed? python print('%x' % 255, '%X' % 255, '%#o' % 8, '%+d' % 0)
- What is printed? python print(float('1e-7'), 0.000001, 1e-6 == 0.000001, 123456789012345678.0)
- What is printed? python print(round(0.5 + 1), round(-0.5 - 1), round(2.5 - 0.0001))
- What is printed? python print(0.1 + 0.2 - 0.3, 0.3 - 0.1 - 0.2, 1 / 49 49, 1 / 10 10)
- What is printed? python import bisect a = [10, 9, 2, 5, 3, 7, 101, 18] tails = [] for x in a: i = bisect.bisectleft(tails, x) if i ==…
- What is printed? python from itertools import product print(list(product('ab', repeat=2)), list(product([0, 1], 'x')))