ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
a = list('abc')
print(a.index('b'), ''.join(a[::-1]), a.pop(0), a)
  1. A. 1 cba a ['a', 'b', 'c']
  2. B. 1 cba a ['b', 'c']
  3. C. 1 cba b ['a', 'c']
  4. D. 1 abc a ['b', 'c']

Correct answer: B. 1 cba a ['b', 'c']

The reversed join is 'cba'. pop(0) removes and returns the first letter, a, leaving ['b', 'c'] for the list shown last.

More Python Programming questions

Exams that ask this topic