Beginner Python (iii)--Dictionary
Beginner Python, mainly finishing some of the learning points, this is a dictionary.
#-*-coding:utf-8-*-D = {1:"name", 2:" Age", 3:"Sex"} #D[1] 1 is not the subscript value, but the key valuePrintD[1] #Add Valueb[r]="addres" PrintD#Update Valuesb[r]="Address" PrintD#when the key value does not exist, this time using D[key] way to take the error, this time#need to verify, such as verifying that 4 and 5 are present in the key value of DPrint5inchDPrintD.get (5) Print4inchDPrintD.get (4) #Get method: Returns None if there is no value for the key, returns the value corresponding to the value of the key if any #Delete an elementD.pop (4) d[3]="class" PrintD" ""list and dict compare list slow, dict fast list takes up memory is small, dict take up memory more dict for space to Exchange time method but must ensure that key is not changed" "
Beginner Python (iii)--Dictionary