# test for Dict
Print (' ==========start Test dict========== ')
names = [' Aa ', ' Bb ', ' Cc ']
Scores = [98, 76, 54]
# # D is equivalent to making a map map
D = {' Aa ': 98, ' Bb ': +, ' Cc ': 54}
Print (' d is ', D)
For name in Names:
Print ('%s is '% name,d[name])
# # Get can not return an error when querying data, return a specified numeric value or string
Print (' xy not exist, result of XY is ', d.get (' xy ',-1))
# # can pass in to determine if the query data exists in Dict
i = 0
Names.append (' Xy ')
While I < 10:
If not names[i] in D:
Print (' Break, names[%d] not exist '% i,names[i])
Break
Print (' names[%d] is '% i,names[i])
Print (' d[%s] is '% names[i],d[names[i])
i = i + 1
Print (' d is ', D)
# #删除映射可用pop
D.pop (' Aa ')
Print (' After Pop,d is ', D)
Print (' =========start Test set========== ')
# #set是一组字符的集合, but the data is automatically de-weighed, add and remove elements can be added and removed, but will still be repeated
s = set ([' A ', ' B ', ' C ', ' a '])
Print (' s is ', s)
S.add (' a ')
S.add (' d ')
Print (' After S.add, S-is ', s)
S.remove (' d ')
Print (' After s.remove, S-is ', s)
S2 = set ([' A ', ' B ', ' e '])
# #set可做 & and | operations
Print (' S2 is ', s2)
Print (' s & S2 is ', S & S2)
Print (' s | S2 is ', s | s2)
A test script that is readily written in the Python learning process-testds.py