dictionary

A dictionary is an associative array or hash table. Strings are often used as keys of dictionaries, and values ​​or tuples can also be used as key types, but because lists and dictionaries can be added and modified, they cannot be used as key types.

person={"name":"Jing-Z","gender":"woman","age":25}

1. Use the key index operator to access dictionary members. The methods of inserting and modifying the dictionary are as follows:

person={"name":"Jing-Z","gender":"woman","age":25}
name = person[ " name " ]        #Access dictionary member 
person[ " gender " ]= " man "     #Modify dictionary member 
person[ " birthday " ]= " 1993.11.18 "      #Add dictionary member 
del person[ " name " ]        # remove dictionary element 
print (person)
result:
    {'gender': 'man', 'age': 25, 'birthday': '1993.11.18'}

2. How to create a list:

person={}
person=dict()

3. To get a list of dictionary keys, convert the dictionary to a list

person={"name":"Jing-Z","gender":"woman","age":25}
syms=list(person)
print(syms)
result:
    ['name', 'gender', 'age']

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324622650&siteId=291194637