ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
try:
'abc'.split('')
except ValueError as e:
print(e)- A. ['a', 'b', 'c']
- B. no output
- C. ValueError
- D. empty separator
Correct answer: D. empty separator
split() with an empty separator raises ValueError with the message 'empty separator'. Only the no-argument form splits into characters, and list(s) is the usual replacement.
More Python Programming questions
- What is printed? python a = [1, 2, 3] for x in a: a.remove(x) print(a)
- What is printed? python print(10 -2, 10 2.0, 10 // 3.0)
- What is printed? python print(all([]), any([]), all(x > 0 for x in [1, 0]))
- What is printed? python print(list(map(lambda x, y: x y, [1, 2, 3], [4, 5])))
- What is printed? python print(sum([[1], [2, 3]], []), sum([[1], [2]], [0]) if False else 'skip')
- What is printed? python print(''.join(sorted(set('hello'), key=ord)))