Python Lists — Python Technical Interview Questions & Answers
Python Lists
Python Lists
- A list is an ordered, changeable row of items. names = ["Asha", "Ravi"]. Index starts at 0: names[0] is Asha. Negative: names[-1] is the last. Length: len(names). This is the collection you will use every day.
- Mutable means you can change it. append("Neha") adds at the end. pop() removes the last. names[0] = "Asha K" overwrites. Slice names[0:2] is a new list — original stays unless you assign back.
- Let’s take this on the board. Start ["Asha", "Ravi"]. append Neha. len is 3. print names[0] → Asha. names[3] → IndexError. append adds one item; extend adds many. Mixing them up is a viva trap.
- Interview line: ordered + mutable + indexable. Tuple is ordered but cannot change. Dict is key→value, not index. Pick list when order and edits both matter.
- Python Lists — output: 3, Asha, then ['Asha', 'Ravi', 'Neha'].
index → 0 1 2
list → [Asha, Ravi, Neha]Technical Interview Tip: Define list with three properties and one method.
Code Examples for Python Lists
Example
# Lists
names = ["Asha", "Ravi"]
names.append("Neha")
print(len(names))
print(names[0])
print(names)
Python Lists — output: 3, Asha, then ['Asha', 'Ravi', 'Neha'].
How to Explain Python Lists to an Interviewer
Explain Lists as if you are teaching a junior — definition, then one tiny script.
A list is an ordered, changeable row of items. Mutable means you can change it.
What does the example print, and why?
Python Lists — output: 3, Asha, then ['Asha', 'Ravi', 'Neha']
What mistake do freshers make with Lists?
Let’s take this on the board.