ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(sum([[1, 2], [3]], []), ''.join(['ab', 'c']), [x for x in 'hey'][::2])
- A. [1, 2] abc ['h', 'y']
- B. [1, 2, 3] ab ['h', 'e']
- C. [1, 2, 3] abc ['h', 'y']
- D. [1, 2, 3] abc ['h', 'e']
Correct answer: C. [1, 2, 3] abc ['h', 'y']
sum with a list start concatenates the inner lists, and join concatenates the strings in order. Taking every second character of hey gives h and y.
More Python Programming questions
- What is printed? python print('%o' % 8 == oct(8)[2:], '%x' % 255 == hex(255)[2:], bin(5)[2:].zfill(4))
- What is printed? python print(-1 2, (-1) 2, -1 -1, (-1) -1)
- What is printed? python print(divmod(-9, 4), divmod(9, -4), -9 % 4, 9 % -4)
- What is printed? python class C: k = 10 try: a = [k + x for x in range(3)] except NameError: a = 'NameError' print(C.a)
- What is printed? python a = [1, 2, 3, 4] a[1:3] = [9] print(a) b = [1, 2, 3, 4] try: b[::2] = [0] except ValueError: print('ValueError')
- What is printed? python from collections import Counter def ways(a, t): dp = Counter({0: 1}) for x in a: nd = Counter(dp) for s, c in…