ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
s = "abcdefghij"
print(s[2:8:3], s[-2:-9:-3], s[8:2:3] == "", s[::4] + s[1::4])
  1. A. cf ifc True aeibf
  2. B. cfi ifc True aeibfj
  3. C. cf ifc True aeibfj
  4. D. cf if True aeibfj

Correct answer: C. cf ifc True aeibfj

s[2:8:3] takes indices 2 and 5 ('c', 'f'). s[-2:-9:-3] starts at index 8 and takes 8, 5, 2 ('i', 'f', 'c'). A positive step with start > stop is empty. s[::4] is 'aei' and s[1::4] is 'bfj'.

More Python Programming questions

Exams that ask this topic