How do I use a Boolean in Python?

后端 未结 7 1654
栀梦
栀梦 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:09

    Boolean types are defined in documentation:
    http://docs.python.org/library/stdtypes.html#boolean-values

    Quoted from doc:

    Boolean values are the two constant objects False and True. They are used to represent truth values (although other values can also be considered false or true). In numeric contexts (for example when used as the argument to an arithmetic operator), they behave like the integers 0 and 1, respectively. The built-in function bool() can be used to cast any value to a Boolean, if the value can be interpreted as a truth value (see section Truth Value Testing above).

    They are written as False and True, respectively.

    So in java code remove braces, change true to True and you will be ok :)

提交回复
热议问题