Operating Environment:
Operating system: Win7 64-bit
Python version: 2.7.12
Ide:pycharm 2017.2
Test code:
Test Python dict 1 and True as a key value
The test demo is as follows:
#!/usr/bin/env python
"Liukang"
Dict_test = {}
Print Dict_test
dict_test[1
Print Dict_test
dict_test[True
Print Dict_test
The results appear as follows:
As can be seen, first we create a new dict:{1:1}, followed by the update into {1:true}. Describes the key value 1=true in Python's dict, but it is important to note that 1 is not equal to True in value.
Similarly, let's test if 0 in Python dict key is equivalent to False:
Test Demo:
Dict_test = {}
Print Dict_test
dict_test[0
Print Dict_test
dict_test[False
Print Dict_test
The results are as follows:
Describes the key value 0=false in Python's dict,
Summarized as follows:
Describes the key values 1=true, 0=false, in Python's dict, but it is important to note that 1 in value is equal to True, and 0 is not equal to False.
Python Dict as a comparison of key values with 1 and true