编程语言
首页 > 编程语言> > python字典

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.

 

 

标签:name,python,david,print,employee,post,NOC,字典
来源: https://www.cnblogs.com/ilifeilong/p/12031227.html