如果你不确定键是否存在,更喜欢dict.get方法。如果找不到key,它允许您返回一个默认值。传统方法dict[key]会引发KeyError异常。
不是
def add_student(): try: students['count'] += 1 except KeyError: students['count'] = 1
而是
def add_student(): students['count'] = students.get('count', 0) + 1
友情链接: json在线解析 通晓查询 糯晒黄历 姓名打分