Variable_name  = {“key name1”: value1, “key name 2: value 2………….}




Variable_name[“key name”]





personInformation = {"Name": "Karan", "Age":37}

print(personInformation)

print(personInformation["Name"])











personInformation = {"Name": "Karan", "Age":37}

print(personInformation)


# Delete Key from dictionary

del personInformation ["Age"]

print(personInformation)











personInformation = {"Name": "Karan", "Age":37}

print(personInformation)

# Clear all items from dictionary
personInformation.clear()
print(personInformation)











personInformation = {"Name": "Karan", "Age":37}

for k,v in personInformation.items():
        print("Key:",k,", Value:",v)











dict = {"key1":1, "key1":2}
print(dict)











nested_dictionary = {"name": "Karan", "address": {"city":"Gurgaon", "country": "India"}}
                         

print("Name:", nested_dictionary["name"])
print("city:", nested_dictionary["address"]["city"])
print("country:", nested_dictionary["address"]["country"])







Posted By  -  Karan Gupta
 
Posted On  -  Thursday, February 14, 2019
 
Updated On  -  Friday, March 29, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250