My_python ~ Storage Related ~

Source: Internet
Author: User
Tags shallow copy

Str,int,list,tuple,dict is a type call that produces an instance

1>>> brand=["Li Ning",'Nike','Adidas','Fish C']2>>> slogan=['everything is possible .','Just Do it','Impossible is nothing','let programming change the world']3>>> Print ("the slogan of Fish C is:", Slogan[brand.index ('Fish C')])4The slogan of Fish C is: Let programming change the world

1>>> dict1={"Li Ning":"everything is possible .",'Nike':"Just Do it",'Adidas':'Impossible is nothing'}2>>> Print (dict1['Li Ning'])3 everything is possible .4>>> Print (dict1["Li Ning"])5Everything is possible.

 1  >>> # dict can only pass in one parameter.  2  >>> dict1=dict ((( f  , 70 ), [   i   ", ])  3  >>> Dict1  4  { f   ": 70 , "  i  : 105 } 

1>>># dict can only pass in one parameter.2>>> Dict1=dict (('F', -),['I', the]))3>>>Dict14{'F': -,'I': the}5>>> dict1['F']=100006>>>Dict17{'F':10000,'I': the}8>>> dict1["QQ"]="Money"9>>>Dict1Ten{'F':10000,'I': the,'QQ':'Money'}
in the list if you are using a function that does not have an error, but in the dictionary, if it does not, it will automatically create a. As above.
1>>> Dict1.fromkeys ((1,2,3))2{1: None,2: None,3: None}3>>> Dict1.fromkeys ((1,2,3),'Num')4{1:'Num',2:'Num',3:'Num'}
If you use Fromkeys directly, you will get an error.
1>>> Dict1=dict1.fromkeys (Range (1,9),'likes')2 Traceback (most recent):3File"<pyshell#0>", line1,inch<module>4Dict1=dict1.fromkeys (Range (1,9),'likes')5Nameerror:name'Dict1'  isNot defined6>>> dict1={}7>>> Dict1=dict1.fromkeys (Range (1,9),'likes')8>>>Dict19{1:'likes',2:'likes',3:'likes',4:'likes',5:'likes',6:'likes',7:'likes',8:'likes'}

1>>> forIinchDict1.items ():2 I3 4     5(1,'likes')6(2,'likes')7(3,'likes')8(4,'likes')9(5,'likes')Ten(6,'likes') One(7,'likes') A(8,'likes')

1>>> forIinchdict1.values ():2 I3 4     5 'likes'6 'likes'7 'likes'8 'likes'9 'likes'Ten 'likes' One 'likes' A 'likes'

1>>> A={1:' One', 2:' Both'}2>>> b=a.copy ()3>>> c=a4>>>ID (a)5486828486>>>ID (b)7488541208>>>ID (c)948682848Ten>>>#So a shallow copy is to put the content in another piece of storage area

add elements in bulk in Dict.
1>>> A={1:' One', 2:' Both'}2>>> b={3:'three', 4:' Four'}3>>> a=a+b4 Traceback (most recent):5File"<pyshell#2>", Line 1,inch<module>6a=a+b7typeerror:unsupported operand type (s) for+:'Dict'  and 'Dict'8>>>A.update (b)9>>>aTen{1:' One', 2:' Both', 3:'three', 4:' Four'} One>>>B.update (a) A>>>b -{1:' One', 2:' Both', 3:'three', 4:' Four'}
a visible dictionary can have a collection of features ~ ' Unique '

My_python ~ Storage Related ~

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.