Python built-in functions (6)--bool

Source: Internet
Author: User

English documents:

class bool ([ x])

Return a Boolean value, i.e. one of True or False . x is converted using the standard Truth testing procedure. If x is False or omitted, this returns False ; otherwise it returns True . boolThe class is a subclass of int (see Numeric Types-int, float, complex). It cannot be subclassed further. Its is only instances is and False True (see Boolean Values).

Description

1. A Boolean value that returns a value of TRUE or False

2. Returns False if the parameter is default

# parameter not passed in False

3. Parameter conversions use standard logic test expressions

3.1 When you pass in a Boolean type, return by the original value

>>> bool (true) True>>> bool (false) False

3.2 An empty string returns False if the string is passed in, otherwise true

>>> bool (') False>>> bool ('0') True

3.3 When the value is passed in, 0 returns false, otherwise true

>>> bool (0) False>>> bool (1) True>>> bool ( -1.0) True

3.4 When passing in tuples, lists, dictionaries, and other objects, the number of elements is null returns FALSE, otherwise true

>>> bool (())#Empty tupleFalse>>> bool ((0,))#non-null tupleTrue>>> bool ([])#Empty listFalse>>> bool ([0])#non-empty listTrue>>> bool ({})#Empty DictionaryFalse>>> BOOL ({'k':'v'})#non-empty dictionariesTrue

Python built-in functions (6)--bool

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.