Python Basic Training Questions 2-tuples, dictionaries

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.