Python Dict as a comparison of key values with 1 and true

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.