ProgrammingModerateWipro NLTH · Python
What is printed?
What is printed?
s = "a,b,,c"
print(s.split(','), s.split(',', 1), " x y ".split())- A. ['a', 'b', 'c'] ['a', 'b,,c'] ['x', 'y']
- B. ['a', 'b', '', 'c'] ['a', 'b,,c'] ['x', 'y']
- C. ['a', 'b', '', 'c'] ['a', 'b,,c'] ['', 'x', 'y', '']
- D. ['a', 'b', '', 'c'] ['a', 'b', ',c'] ['x', 'y']
Correct answer: B. ['a', 'b', '', 'c'] ['a', 'b,,c'] ['x', 'y']
split(',') keeps the empty field; maxsplit=1 splits only at the first comma; split() with no argument discards runs of whitespace.
More Python Programming questions
- What is printed? python print(list(zip('abc', range(5))), dict(zip('ab', [1, 2, 3])))
- What is printed? python def f(x, acc=[]): acc.append(x) return len(acc) print(f(1), f(2), f(3, []), f(4))
- What is printed? python print(all([]), any([]), all([0]), any([[]]), any([[0]]))
- What is printed? python w = ['pear', 'fig', 'apple', 'kiwi', 'date'] print(sorted(w, key=len), sorted(w, key=len, reverse=True))
- What is printed? python print(7 // 2, -7 // 2, 7 % -3, divmod(-7, 2), 2 -1)
- What is printed? python print({x % 3 for x in range(10)}, {x: x x for x in range(3)})