Dictionary Methods
keys()
Return a dynamic view of all keys in the dictionary.
dict.keys()
dict.keys() returns a view object that displays all the keys stored in the dictionary.
It preserves insertion order and updates dynamically whenever the dictionary changes.
Returns
A dict_keys view of all dictionary keys.
Try it
Run it and change it
user = {"username": "py_master", "level": 42, "xp": 9850}
print(list(user.keys()))Worth knowing
- Set operations: Key views behave like sets; you can perform union (
|), intersection (&), and difference (-) between two key views.