web123456

4 ways to create dictionaries in Python

1. Use braces to create a dictionary person = {"name":"Zhang San","age":18,"pay":40000,"job":"Python Engineer"} 2. Use keyword parameters and type constructors to create dictionary person = dict(name="Zhang San",age=18,pay=40000,job="Python Engineer") 3. Use the zip function to link names/value lists together to create a dictionary keys = ["name","age","pay","job"] values ​​= ["Zhang San", 18,40000,"Python Engineer"] person = dict(zip(keys,values)) 4. Use fromkeys to create a dictionary through a sequence of keys and optional initial values ​​for all keys. keys = ["name","age","pay","job"] person = (keys,"?")