ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print('a-b_c d'.split('-'), 'a-b_c d'.replace('-', ' ').split('_'), 'a-b'.partition('-')[0])- A. ['a', 'b'] ['a b', 'c d'] a
- B. ['a', 'b_c d'] ['a b', 'c d'] a
- C. ['a', 'b_c d'] ['a', 'b c'] a
- D. ['a', 'b_c d'] ['a b', 'c d'] b
Correct answer: B. ['a', 'b_c d'] ['a b', 'c d'] a
split('-') breaks at the hyphen only, so the underscore stays inside the second piece. Replacing hyphens with spaces and then splitting on the underscore gives two pieces, and partition returns the text before the first hyphen.
More Python Programming questions
- What is printed? python print(sum([1] 105) == 105, sum([0.5] 105) == 5e4, 1/3 + 1/3 + 1/3 == 1.0, 0.7 + 0.2 + 0.1 == 1.0)
- What is printed? python from fractions import Fraction print(Fraction(7, 3) > 2, float(Fraction(7, 3)), Fraction(7, 3) // 1, Fraction(-7…
- What is printed? python print(1 + 2 3 2 // 4 % 5, (1 + 2) 3 2 // 4 % 5, -2 2, (-2) 2)
- What is printed? python print(max('zebra', 'Zebra'), min('zebra', 'Zebra'), 'apple' > 'Apple', 'Z' < 'a')
- What is printed? python x = 5 print(x.add(3), (5).mod(-3), (-5).mod(3), int.floordiv(-5, 3))
- What is printed? python print('ab'.rjust(5, ''), 'ab'.ljust(5, '-'), 'ab'.center(5, '.'), 'ab'.center(6, '.'))