PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

dict.keys()

← All stacks

Theory

261/268

dict.keys()

dict.keys() works on a dictionary — labelled data like marks["Asha"] = 90. Keys map to values. Loop with .items() when you need both.

dict.keys() — output — ['Asha', 'Ravi'].

Trap for dict.keys() — writing d[missing] in a viva. Prefer get when the key might not exist.

Diagram
{ "Asha": 90, "Ravi": 85 }
         │           │
        key        value
Exam tip

get vs [] — one sentence + tiny dict of marks.

Example

# dict.keys()
print(list({"Asha": 90, "Ravi": 85}.keys()))

dict.keys() — output: ['Asha', 'Ravi'].

Short notes

  • Defdict.keys() works on a dictionary.
  • Ruledict.keys() — get when key may miss.
  • Rememberdict.keys() — items() → key and value.
  • Trapdict.keys() — d[missing] → KeyError.

Questions

1

Explain dict.keys() as if you are teaching a junior — definition, then one tiny script.

2

What does the example print, and why?

3

What mistake do freshers make with dict.keys()?

Previous← dict.fromkeys()NextPlotly + Matplotlib →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.