How Shallow and Deep Copies Work in Python

A few weeks ago I was testing a small feature nothing fancy, just duplicating a dictionary before running an update, the way you're taught to "be safe." I only touched the copy. And somehow, the original changed too. I hadn't touched it. I hadn't reassigned it. It just changed.It wasn't a Python bug. It was something I'd been getting wrong without realizing it: a variable doesn't hold an object it holds a reference to one. Once that clicked, this entire category of "silent" bugs stopped feeling random.What You Expectoriginal = {"name": "Sohel", "skills": ["Python", "JS"]} copy_dict = original.copy() copy_dict["skills"].append("React") print(original["skills"]) You'd expect this to
…