Python List Append Behavior Confusion

If you get this right… your Python fundamentals are solid 😏 Python Series — Day 4 🧠 This one has confused a lot of developers (including me once 👀) What will be the output? def add_item(item, lst=[]): lst.append(item) return lst print(add_item(1)) print(add_item(2)) print(add_item(3)) Options: A. [1] [2] [3] B. [1] [1, 2] [1, 2, 3] C. Error D. Something unexpected 👀 Don’t rush this one. 👉 Think: Is the list created every time… or reused? Drop your answer 👇 Let’s see who gets it right 🔥 Answer tomorrow 🚀 #Python #CodingChallenge #LearningInPublic #Tech #DataEngineering

  • text

To view or add a comment, sign in

Explore content categories