Python boolean value

Source: Internet
Author: User
下列对象的布尔值都是False:NONE;False(布尔类型)所有的值为零的数       0(整型)       0.0(浮点型)       0L(长整型)       0.0+0.0j(复数)""(空字符串)[](空列表)()(空元组){}(空字典)

Dictionaries can also be user Boolean tested

dict_1 = {}dict_2 = {‘a‘:123} if dict_1:    print(‘dict_1 is not null‘)else:    print(‘dict_1 is null‘) if dict_2:    print(‘dict_2 is not null‘)else:    print(‘dict_2 is null‘)

Output:

dict_1 is nulldict_2 is not null

It can be seen that the dictionary type is also used for Boolean testing.

Python boolean value

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.