Think you know how lists work in Python?
Let’s see if you can get this right! 🧠🐍
📌 Code:
python
list1 = [1, 2, 3]
list2 = list1
list2.append(4)
print(list1)
✅ Options:
A) [1, 2, 3]
B) [1, 2, 3, 4]
C) [1, 2, 3], [1, 2, 3, 4]
D) Error
🧠 Correct Answer:
B) [1, 2, 3, 4]
💡 Explanation:
In Python, when you do list2 = list1, both variables reference the same list in memory.
So when you do list2.append(4), it also affects list1!
👉 Always be careful when copying lists—use .copy() or list() for a true copy!
👇 Drop your guess in the comments before watching!
✅ Like, Share & Subscribe for more Python tricks and interview insights.
🔥 Hashtags:
#Python #PythonTips #LearnToCode #TechShorts #CodeNewbie #PythonLists #InterviewPrep #100DaysOfCode #CodingChallenge #DeveloperLife