python is determined whether there is a key dictionary

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/Nash_Cyk/article/details/79083426

When using the python do background development, transfer data to json format, this time we will often encounter fields with json data conversion, commonly used methods we can use import json, json use of loads and dumps
Code: also called the sequence of dumps
decoding: it is also known for its anti-serialization loads
after the conversion when the data transmission we generally will parse the data dictionary, this time tend to judge the dictionary key, there are two common ways, one is has_key, the other is the use in not in, the latter better efficiency.

dict = {'Alice': '12', 'Beth': '34', 'Cecil': '56'}
if 'Alice' in dict.keys():
      if dict['Alice'] == '12':
            print('success')

Guess you like

Origin blog.csdn.net/Nash_Cyk/article/details/79083426