要确定一个键是否在字典中,就像在列表中一样
nums = { 1: "one", 2: "two", 3: "three", } print(1 in nums) print("three" in nums) print(4 not in nums)
结果
True False True
0