1 #The first part:2 #Create a dictionary3Dict_test = {}#This is an empty dictionary.4Dict1 =dict ()5 #Add a key-value pair6dict1['Name_key'] ='Name_value'7 #Accessing Dictionaries8 Print(dict1['Name_key'])9 #to modify a value in a dictionaryTendict1['Name_key'] ='Jack' One Print(dict1['Name_key']) A #Delete key-value pairs - deldict1['Name_key'] - the #Part II: -Dict2 = { - 'name':'Jack', - ' Age': 21, + } - #traversing key-value pairs + forName,ageinchDict2.items (): A Print(name,age) at #traverse all keys (sequential, non-sequential) - #No order - forKeyinchDict2.keys (): - Print(Key) - #Order - forKeyinchSorted (Dict2.keys ()): in Print(Key) - #Traverse All Values to forValueinchdict2.values (): + Print(value) - the #Part III: * #List Dictionary $People = [{'name':'Jack'},{'name':'son'},{'name':'Father'}]Panax Notoginseng #store list in dictionary -Family = { the 'Father_name':'Jack', + 'Son_name':['Son1,son2,son3'] A } the #Store dictionary in dictionary +User_dict = { - 'User_info':{'name':'Jack',' Age': 21} $}
Python Basics-Dictionary Chapter