使用 dict() 创建字典
使用 dict() 构造函数创建字典
以下实例为学习使用 dict() 构造函数创建字典,具体代码如下:
# Filename : example.py
# Author by : www.lidihuo.com
thisdict = dict(brand="Porsche", model="911", year=1963)
# note that keywords are not string literals
# note the use of equals rather than colon for the assignment
print(thisdict)
执行以上代码输出结果为:
# Filename : example.py
# Author by : www.lidihuo.com
{'brand': 'Porsche', 'model': '911', 'year': 1963}