Home › Interview Questions › What is the output of this Python code that concat…

What is the output of this Python code that concatenates two lists, slices the last two items, and replaces 'english' with 'maths'?

🟢 Easy Conceptual Junior level
1Times asked
Sep 2026Last seen
Sep 2026First seen

💡 Model Answer

The code performs three main steps:

  1. It concatenates list_a and list_b using the + operator, producing ['science', 'social', 'maths', 'english'].
  2. It slices the last two elements of the combined list, yielding ['maths', 'english'].
  3. It finds the index of the string "english" in the combined list and replaces that element with "maths", resulting in ['science', 'social', 'maths', 'maths'].

The printed output will therefore be:

['science', 'social', 'maths', 'english']

['maths', 'english']

['science', 'social', 'maths', 'maths']

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500