一个字典如下所示,判断其中是否存在一个 "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