4/29
Part 1 of 6 · The formatLearn and do
delete says whether it removed something
Last, delete:
delete(key, field)removes the field. It returnsTrueif the field existed, andFalseif it didn't.
in asks whether a dict has a key, and del removes one. On the phone book:
ana = phones.get("ana", {})
print("home" in ana, "work" in ana)
del ana["home"]
print(phones)
True False
{'ana': {}}
del on a key that isn't there raises a KeyError, so check with in first. Check the field, not its value: a field can hold the empty string, and it still exists.
In the editor, set and get are written, and you write delete. It prints True, then False, then what's left of the records.