Python Dictionaries Made Easy π₯ | Key-Value Pairs, get() & Updates | Python Lesson 14
About this video
Learn Python Dictionaries β Key-Value Data step by step with PEARL INSTITUTE BATALA.
In Lesson 14 of our Python + Machine Learning Practical Course, you will learn how dictionaries store structured information using meaningful key : value pairs.
This lesson is explained in easy Hindi/Hinglish with practical coding examples, common mistakes and a quick practice question.
β In this lesson you will learn:
β’ What is a Dictionary in Python?
β’ Key : Value Pairs
β’ How to Create a Dictionary
β’ Access Values Using Keys
β’ Why Dictionaries Use Keys Instead of Numeric Indexes
β’ Updating Existing Values
β’ Adding New Key-Value Pairs
β’ Why Dictionary Keys Should Be Unique
β’ Using len() with Dictionaries
β’ Practical Student Record Example
β’ Understanding KeyError
β’ Safe Access Using get()
β’ Common Dictionary Mistakes
β’ Quick Practice Question
β’ Use of Dictionaries in Machine Learning
π» Basic Dictionary Example
student = {
"name": "Aman",
"age": 21,
"course": "Python"
}
Access a value:
print(student["name"])
Output:
Aman
π Update an Existing Value
student["age"] = 22
Now:
print(student["age"])
Output:
22
β Add a New Key-Value Pair
student["city"] = "Batala"
Now the dictionary contains another piece of information.
β οΈ Important Rule: Dictionary Keys Must Be Unique
If the same key appears again, the later value replaces the earlier value.
Example:
student = {"name": "Aman", "name": "Simran"}
The final value of "name" will be:
Simran
π₯ Avoid KeyError with get()
This may produce an error if "city" does not exist:
student["city"]
Safer approach:
student.get("city", "Not Found")
Output:
Not Found
This makes get() very useful when a key may or may not exist.
π― Perfect For:
Python Beginners
Coding Beginners
BCA Students
B.Sc. IT Students
MCA Students
School & College Students
Programming Students
Machine Learning Beginners
Computer Course Students
Students Learning Python from Scratch
π€ Machine Learning Connection
Python Dictionaries are useful for representing:
β’ Structured Records
β’ Feature Names
β’ Model Parameters
β’ Configuration Settings
β’ Student or Customer Data
β’ Data Exchanged Between Python Components
π Course: Python + Machine Learning Practical Course
π Lesson 14: Python Dictionaries β Key-Value Data
π« PEARL INSTITUTE BATALA
π Near Bus Stand, Jalandhar Road, BATALA
π Call / WhatsApp: 7814976999
π www.PEARLINSTITUTE.in
π©βπ« Institute Head: Mrs Sonika Malhotra
π Subscribe to continue learning Python step by step.
π Next Lesson: List Methods, Slicing and Useful List Patterns