python中创建关联数组(字典)的两种方法

2022-04-14 00:00:00 数组 字典 两种

关联数组在python中叫字典,非常有用,下面是定义字典的两种方法

"""
皮蛋编程(https://www.pidancode.com)
创建日期:2022/4/3
功能描述:python中创建关联数组(字典)的两种方法
"""

d1 = {"name": "donuts", "type": "chocolate", "quantity": 10}

d2 = dict(name="donuts", type="chocolate", quantity=10)
assert d1 == d2

代码在python3.9下测试通过,两种方法创建的字典完全一样

相关文章