How do I use a Boolean in Python?

后端 未结 7 1656
栀梦
栀梦 2020-12-02 12:31

Does Python actually contain a Boolean value? I know that you can do:

checker = 1
if checker:
    #dostuff

But I\'m quite pedantic and enjo

7条回答
  •  广开言路
    2020-12-02 13:23

    Yes, there is a bool data type (which inherits from int and has only two values: True and False).

    But also Python has the boolean-able concept for every object, which is used when function bool([x]) is called.

    See more: object.nonzero and boolean-value-of-objects-in-python.

提交回复
热议问题