aa={"a":2,"b":1} for i in range(10): aa["a"]=aa["a"]-i print(aa["a"]) try: ab=aa["c"]-1 except KeyError: #记录特定异常 print("没有相应的关键") try: print(ab) except BaseException as e: #抓取并记录所有异常 print("变量不存在") print(e)