Python004: Python中的字典和集合以及其增删改查
>>>dictionary = {'name': '董照诚','Age':23,'Score':100}
>>>dictionary[712:'实验室']
>>>dictionary
{'name': '董照诚','Age':23,'Score':100,712:'实验室'}
del dictionary['name']
del dictionary
dictionary.clear()
dict = {}
dict = {'name': '董照诚','Age':23,'Score':100}
len(dict)
str(dict)
type(dict)
key in dict
dict.clear()
dict.copy()
dict.fromkeys(seq[,value])
dict.get(key,default = None)
dict.setdefault(key,default = None)
>>>dict.items()
dict_items([('name', '董照诚'), ('Age', 23), ('Score', 100)])
>>>type(dict.items())
<class 'dict_items'>
>>>dict.keys()
dict_keys(['name', 'Age', 'Score'])
>>>list(dict.keys())
['name', 'Age', 'Score']
dict.values()
dict.pop(key)
dict.popitems()
>>>mySet = {'apple','orange','apple','pear','banana'}
>>>mySet
{'banana', 'apple', 'pear', 'orange'}
>>>
...
>>> a = set('abracadabra')
>>> b = set('alacazam')
>>> a
{'a', 'r', 'b', 'c', 'd'}
>>> a - b
{'r', 'd', 'b'}
>>> a | b
{'a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'}
>>> a & b
{'a', 'c'}
>>> a ^ b
{'r', 'd', 'b', 'm', 'z', 'l'}
mySet.add(x)
mySet.update(x)
mySet.remove(x)
mySet.discard(x)
mySet.pop()
mySet.remove()
mySet.Clear()
xxx in mySet
len(mySet)
mySet.copy()
mySet.difference(set2)
mySet.difference_update(set2)
mySet.intersection(set1,set2,....)
mySet.intersection_update(set1,set2,....)
mySet.symmetric_difference(set2)
mySet.symmetric_difference_update(set2)
mySet.isdisjoint()
mySet.issubset(y)
mySet.isuperset(y)
mySet.union(y)