ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
s = 'one two three'
print(s.split(' '), len(s.split()), s.split(None, 1)[1], '-'.join(s.split()))- A. ['one', 'two', '', 'three'] 3 two three one-two-three
- B. ['one', 'two', 'four'] 3 two three one-two-three
- C. ['one', 'two', '', 'three'] 2 two three one-two-three
- D. ['one', 'two', '', 'three'] 3 two three one-two-threes
Correct answer: A. ['one', 'two', '', 'three'] 3 two three one-two-three
split(' ') keeps an empty string for the double space, while split() with no argument collapses runs of spaces. split(None, 1) stops after the first word and keeps the rest unchanged.
More Python Programming questions
- What is printed? python print('ab'.ljust(4, '') + '|', 'ab'.rjust(4, ''), 'ab'.zfill(4), '12'.zfill(1))
- What is printed? python print('%s and %s' % ('A', 'B'), '%(x)d-%(x)05.1f' % {'x': 3}, '%%%d' % 5)
- What is printed? python print(1 / 2 + 1 // 2 + 1 % 2, 1 / 2 2 == 1, 3 1 / 2 == 3 (1 / 2))
- What is printed? python print(0x10 + 0o10 + 0b10, 10 + 0x1, 1e1 + 1, 1j 1j)
- What is printed? python print(max(-0.0, 0), min(0, -0.0), -0.0 + 0, 0 - 0.0)
- What is printed? python a = 10 b = 3 print(a / b b == a, a // b b + a % b == a, a % b / b == (a / b) % 1)