Note on python__2021-07-05Python练习使用字典dict+list

Posted topia_csdn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Note on python__2021-07-05Python练习使用字典dict+list相关的知识,希望对你有一定的参考价值。

字典初级使用

>>> 价格 = 【】
  File "<stdin>", line 1
    价格 = 【】
         ^
SyntaxError: invalid character '【' (U+3010)
>>> a价格 = []
>>> a价格
[]
>>> a价格 = {'苹果':1,'香蕉':1.5,'梨子':2,'橘子':0.1}
>>> a价格['苹果']
1
>>> a价格['橘子']
0.1
>>>

字典dic加list列表高级使用

>>>character = ['happy','angry','sad','joy','scare']
>>> classmates = {'Adam':character[0],'Bill':character[1],'Chen':character[0],'Den':character[4],'Ella':character[3],'Fill':character[2],'Gerta': character [0]}
>>> classmates [ 'Gerta' ]
'happy'
>>> classmates [ 'Chen' ]
'happy'
>>> classmates [ 'Bill' ]
'angry'
>>> classmates [ 'Den' ]
'scare'
>>>

优点:方便复制粘贴调用list列表里的信息

以上是关于Note on python__2021-07-05Python练习使用字典dict+list的主要内容,如果未能解决你的问题,请参考以下文章

Note on python__2021-07-05Python练习使用字典dict+list

Note on python__2021年7月2日Python练习使用list和tuple

Note on python__2021-07-05Python练习使用if-else条件选择+list列表——>age_selector

python note 13 内置函数

Python_Note_Preview_03_URL

Python Note_2