ProgrammingHardInfosys · Accenture · Capgemini pattern
What is printed on the third line?
What is printed on the third line?
print('a,b,,c'.split(','))
print(' a b '.split())
print(' a b '.split(' '))- A. ['a', 'b', 'c']
- B. ['', 'a', 'x', '']
- C. ['a', 'b', 'c', 'd']
- D. ['', 'a', 'b', '']
Correct answer: D. ['', 'a', 'b', '']
split() with no argument collapses runs of whitespace and drops empty strings at the ends. split(' ') keeps an empty string for every separator it finds, including the leading and trailing ones.
More Python Programming questions
- What is printed? python print(int('0x1f', 16), int('0x1f', 0), int(' -12 '), int('1000'))
- What is printed? python print(bin(-5), format(-5, '08b'), (-5) & 0xFF, format(-5 & 0xFF, '08b'))
- What is printed? python print(divmod(-17, 5), divmod(17, -5), divmod(-17.0, 5))
- What is printed? python print(7 // -2, -7 // 2, 7.0 // -2, -7.0 % 2)
- What is printed? python print(abs(-0.0), -0.0 == 0.0, str(-0.0), str(-0.0 + 0.0))
- What is printed? python print(sum([0.1] 10) == 1.0, sum([0.1] 10), sum([0.1] 10, 0) == 1.0)