一个字典如下所示,判断其中是否存在一个 "platform" 的值为 "main" ,字典中并无此值,但打印结果却显示存在,做个记录希望以后能理解
case = {"x": {"a": "append", "b": "blue"}, "y": {"c": "class"}} if "main" in case.get("platform", ["main"]): print(case.get("platform", ["main"])) print("main" in case.get("platform", ["main"]))
输出结果如下:
[‘main‘] True
字典的get方法有一点疑惑,明明不存在为什么判断为true并且可以打印出结果
原文:https://www.cnblogs.com/zhenghiber/p/15237542.html