dict.keys() Keys view
Last updated: 2026-09-22
dict.keys() Keys view
dict.keys() returns a view of keys; supports set operations.
| Category | Dict Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
dict.keys()
Returns:A dict_keys view object; supports set operations (& | - ^).
Mutates the original:No (returns a new object)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
['a', 'b']
{'a'}
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat does keys() return?
AA dict_keys view object supporting membership checks: k in d.keys() is equivalent to k in d, both O(1).
QDoes it support set operations?
AYes, & | - ^: d1.keys() & d2.keys() finds the keys common to two dicts.
QDoes the view change dynamically?
AYes, the view reflects changes to the dict's keys in real time.