ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print('abc'[1:][::-1], 'abc'[::-1][1:], 'abcdef'[::-2][:2])- A. bc cb fd
- B. cb ba fe
- C. cb ba fdb
- D. cb ba fd
Correct answer: D. cb ba fd
Slices apply left to right: 'bc' reversed is 'cb', and 'cba' from index 1 is 'ba'. [::-2] of 'abcdef' takes f, d, b, and the first two of those are fd.
More Python Programming questions
- What is printed? python print(float('nan') != float('nan'), float('inf') == float('inf'), float('inf') - float('inf') == 0, -float('inf')…
- What is printed? python x = [1, 2, 3] y = x x = x + [4] print(y, x, y is x)
- What is printed? python print(int('٤٢'), '٤٢'.isnumeric(), ' 42n'.isdigit(), int('42n'))
- What is printed? python from collections import Counter c = Counter() c['a'] += 2 c.update('ab') print(c['a'], c['b'], c['z']…
- What is printed? python print(pow(2, 1018, 109 + 7) == pow(2, 1018 % (109 + 6), 109 + 7))
- What is printed? python print(7 // 0.5, 7 % 0.5, 0.5 7 // 1, 1e308 10 == float('inf'))