ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(len(' a b '.split()), len(' a b '.split(' ')), len('a\nb\n'.splitlines()), len('a\nb\n'.split('\n')))- A. 2 4 2 3
- B. 2 3 2 3
- C. 2 4 3 3
- D. 2 4 2 4
Correct answer: A. 2 4 2 3
split() ignores all whitespace runs, while split(' ') keeps empty strings at both ends. splitlines does not create an empty last item, but split('\n') does.
More Python Programming questions
- What is printed? python print(list('abc'.encode()), 'abc'.encode()[0] + 1, bytes('hi', 'ascii') == b'hi')
- What is printed? python x = 17 print(x.bitlength(), (x & -x).bitlength(), x.bitcount(), bin(x)[2:].zfill(8))
- What is printed? python print(int(2.5 4) // 3, int(10 / 4 2), 10 // 4 2, 10 / 4 // 2)
- What is printed? python print(float(1) / 3 + float(2) / 3 == 1.0, 0.1 0.1 100 == 1.0, 1 - 0.1 9 == 0.1)
- What is printed? python print(f"{0.1:.20f}")
- What is printed? python def nge(a): st, res = [], [-1] len(a) for i, x in enumerate(a): while st and a[st[-1]] < x: res[st.pop()] = x…