ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print('a,b'.split(',', -1), 'a,b,c'.split(',', 0), 'a b c'.split(maxsplit=1))- A. ['a', 'b'] ['a', 'b', 'd'] ['a', 'b c']
- B. ['a', 'b'] ['a,b,c'] ['a', 'b c']
- C. ['a', 'b'] ['a,b,c'] ['a', 'b', 'x']
- D. ['a'] ['a,b,c'] ['a', 'b c']
Correct answer: B. ['a', 'b'] ['a,b,c'] ['a', 'b c']
A negative maxsplit means no limit, so 'a,b' splits fully. A maxsplit of 0 makes no splits at all, and split with maxsplit 1 on whitespace stops after the first field.
More Python Programming questions
- What is printed? python print(bytes.fromhex('de ad'), (255).tobytes(2), bytes([1, 2]).hex(' '))
- What is printed? python print(round(1.5, 0), round(-2.5), round(2.5, 0) == 2, round(0.5, 0) == 0)
- What is printed? python from math import floor, ceil, trunc print(floor(-0.5), ceil(-0.5), trunc(-0.5), floor(2))
- What is printed? python print(sorted([3, 1, 2], key=lambda x: -x)[0], sorted('bca', key=lambda c: c > 'a'))
- What is printed? python print(int('10', 36) == 36, int('Z', 36), int('z', 36) + 1, int('10', 2) == 2)
- What is printed? python x = [1, 2, 3] print(x.pop(), x.pop(0), x, x.insert(0, 9) or x)