ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print('abc'.partition('x'), 'a=b=c'.partition('='), 'a=b=c'.rpartition('='))- A. ('abc', 'x', '') ('a', '=', 'b=c') ('a=b', '=', 'c')
- B. ('abc', '', '') ('a', '=', 'b') ('a=b', '=', 'c')
- C. ('abc', '', '') ('a', '=', 'b=c') ('a=b', '=', 'c')
- D. ('abc',) ('a', 'b', 'c') ('a=b', '=')
Correct answer: C. ('abc', '', '') ('a', '=', 'b=c') ('a=b', '=', 'c')
partition() returns three parts, with empty separators when the text is missing. partition splits at the first '=' and rpartition splits at the last, which is why the two results differ.
More Python Programming questions
- What is printed? python s = 'abcdefgh' print(s[::-2], s[1::3], s[-3:-6:-1], s[::-1][::2])
- What is printed? python print('%05.1f|%x|%o|%e' % (3.14159, 255, 8, 12345.678))
- What is printed? python print(f'{-5:+}', f'{5:+}', f'{3.0:g}', f'{1e6:g}', f'{1e-5:g}', f'{123456789.0:g}')
- What is printed? python print(f'{12345678:,}', f'{0.5:.0%}', f'{2.5:.0f}', f'{3.5:.0f}', f'{-0.4:.0f}')
- What is printed? python print(repr(1e16), repr(1e15 + 0.3), 1e16 == 1016, 1e16 + 1 == 1e16)
- What is printed? python print(10 -2, 10.0 -2, 1000 10, 2 -1 4)