python字典

字典即为放在花括号{}中一系列键值对的集合,值可以使数字、字符、集合等。

>>> employee_1 = {'name': 'david', 'dept': 'ops', 'post': 'NOC', 'salary': 9999}
>>>
>>> type(employee_1)
<class 'dict'>

访问字典中的数据

>>> print(employee_1)
{'name': 'david', 'dept': 'ops', 'post': 'NOC', 'salary': 9999}
>>> 
>>> print(employee_1['name'])
david
>>>
>>> print("Welcome our new colleague: " + employee_1['name'] + ", " + "His post is: " + employee_1['post'] + ".")
Welcome our new colleague: david, His post is: NOC.

 

 

上一篇:风言风语


下一篇:2小时快速搭建第一个小程序,有可能吗