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

Python · Theory

Python Dictionary

← All stacks

Theory

37/268

Python Dictionary

A dictionary maps a key to a value — a labelled lookup. person = {"name": "Asha", "age": 21}. person["name"] is Asha. Keys must be hashable (str, int, tuple of hashables). Values can be anything. You add, update, and delete pairs anytime. Loop with .items() when you need both key and value.

person["email"] on a missing key → KeyError. person.get("email", "-") returns "-". Prefer get when the key might miss. Dict is not a list — you don’t look up by 0, 1, 2 unless those numbers are actually keys.

Python Dictionary — output — 90 then 0. Asha exists. Neha missing → get default 0, no crash.

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

KeyError vs dict.get default.

Example

# Dictionary
marks = {"Asha": 90, "Ravi": 85}
print(marks["Asha"])
print(marks.get("Neha", 0))

Python Dictionary — output: 90 then 0. Asha exists. Neha missing → get default 0, no crash.

Short notes

  • DefKey → value map.
  • RuleHashable keys.
  • Trap[] missing → KeyError. Use get.

Questions

1

Explain Dictionary 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 Dictionary?

Previous← Python Set MethodsNextPython Dictionary Methods →
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.