ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
s = 'abc'
print(s * 2 == 'abcabc', s[1:] + s[:1], s[-1:] + s[:-1], len('ab' * 0))
  1. A. True bca cab 0
  2. B. True cab bca 0
  3. C. True bca bca 0
  4. D. False bca cab 0

Correct answer: A. True bca cab 0

Slicing rotates the string both ways: s[1:] + s[:1] gives 'bca' and s[-1:] + s[:-1] gives 'cab'. Repetition by zero gives an empty string.

More Python Programming questions

Exams that ask this topic