ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
s = "abc"
print(repr(s[1:1] + s[3:] + s[-1:-2]), s[0:0] == s[5:9], len(s[-5:5]), s[True:])
  1. A. 'c' True 3 bc
  2. B. '' False 3 bc
  3. C. '' True 3 bc
  4. D. '' True 3 TypeError

Correct answer: C. '' True 3 bc

All three slices are empty (s[-1:-2] runs forward from index 2 to 1). Out-of-range bounds are clipped, so s[5:9] is '' and s[-5:5] is the whole string. True is an int equal to 1, so s[True:] is 'bc'.

More Python Programming questions

Exams that ask this topic