1, the judging value in the tuple
>>> a = (1, 2, 3, 4, ten ) in atrue' in a Fal Se
2, modify the values in the tuple, because the tuple cannot be directly modified, you can first turn him into a list, after modifying through the list, assign to a new tuple object
>>> a = (ten, +, + )>>> l = list (a)>>> l[0] = 100>>> T = Tuple (L)>>> T (+, +, +)>>> ID (a)139920488716168>> > ID (t)139920488447152>>> type (a)'tuple'>>> > type (t)'tuple'
3, add a value to the collection, delete a value, find the intersection and the set
>>>Aset (['a','C','b','e','D','g','F'])>>> A.add ('GHOSTWU' )>>>Aset (['a','C','b','e','D','g','F','GHOSTWU'])>>> A.remove ('g' )>>>Aset (['a','C','b','e','D','F','GHOSTWU'])>>> B = Set ("ABCDLMN" )>>> A &bset (['a','C','b','D'])>>> A |bset (['a','C','b','e','D','F','m','L','N','GHOSTWU'])>>>
4, using a dictionary to achieve a student performance small system, after the addition, modification, deletion, sorting and other operations
>>> student = {'GHOSTWU': {'name':'GHOSTWU',' Age': 20,'score': {'Math': 78,'中文版': 66,'python': 75 } } }>>>student{'GHOSTWU': {' Age': 20,'score': {'python': 75,'Math': 78,'中文版': 66},'name':'GHOSTWU'}}>>> student['Tom'] = {'name':'Tom',' Age': 21,'score': {'Math': 60,'中文版': 80,'python': 90 } }>>>student{'GHOSTWU': {' Age': 20,'score': {'python': 75,'Math': 78,'中文版': 66},'name':'GHOSTWU'},'Tom': {' Age': 21,'score': {'python': 90,'Math': 60,'中文版': 80},'name':'Tom'}}>>> student['GHOSTWU']['score']['PHP'] = 90>>> student['Tom']['score']['PHP'] = 50>>> student['GHOSTWU']['score']['Math'] = 30>>>delstudent['GHOSTWU'][' Age']>>> Score1 = student['GHOSTWU']['score'].values ()>>>score1[75, 90, 30, 66]>>>Score1.sort ()>>>score1[30, 66, 75, 90]>>> Student.pop ('Address','Shenzhen' )'Shenzhen'>>>student{'GHOSTWU': {'score': {'python': 75,'PHP': 90,'Math': 30,'中文版': 66},'name':'GHOSTWU'},'Tom': {' Age': 21,'score': {'python': 90,'PHP': 50,'Math': 60,'中文版': 80},'name':'Tom'}}>>>
Python Basic Training Questions 2-tuples, dictionaries