Important Notice:

Dictionaries in Python

Dictionaries in Python

18 views 1 min read

Dictionaries

A dictionary is a collection of key-value pairs.

student = {\n "name": "Rahul",\n "age": 20,\n "marks": 95\n}Operationsstudent["name"] # Rahul\nstudent["age"] = 21 # Update\nstudent["city"] = "Delhi" # Add newDictionary MethodsMethodDescriptionkeys()All keysvalues()All valuesitems()Key-value pairsget(key)Get value safelypop(key)Remove keyupdate()Merge dictIterationfor key, value in student.items():\n print(key, ":", value)