ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
s = 'abc'
print(s * 0 == '', s[::-1][::-1] == s, s[1:-1] * 2, s[-3:-1])
  1. A. True True b ab
  2. B. True False bb ab
  3. C. True True bb a
  4. D. True True bb ab

Correct answer: D. True True bb ab

s[1:-1] is 'b', and repeating it twice gives 'bb'. Reversing a string twice returns the original, and s[-3:-1] takes the first two characters, 'ab'.

More Python Programming questions

Exams that ask this topic