You can use Python dictionary method pop() or del() to remove a key from a Python dictionary as shown in the below example –
1 2 3 4 5 6 7 8 9 10 11 12 13 |
d = {"name": "debjeet","age": 35} print(d) d.pop("age", None) print(d) del d["name"] print(d) ## Returns ## {'name': 'debjeet', 'age': 35} ## {'name': 'debjeet'} ## {} ## Use pop method if you are not use of the key existance in the dictionary |