[root@pc1 test1]# python3 Python 3.11.4 (main, Jul 5 2023, 14:15:25) [GCC 11.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from collections import defaultdict >>> dict1 = defaultdict(int) >>> dict2 = dict() >>> dict1 defaultdict(<class 'int'>, {}) >>> dict2 {} >>> dict1["aa"] += 5 >>> dict1 defaultdict(<class 'int'>, {'aa': 5}) >>> dict2["aa"] += 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: 'aa' >>> dict2 {}
标签:defaultdict,aa,dict1,help,dict2,test1 From: https://www.cnblogs.com/liujiaxin2018/p/17762408.html