On this page
builtins.bool
Prev: builtins.BlockingIOError | Up: builtins | Next: builtins.breakpoint
Rel: builtins.abs, builtins.aiter, builtins.all, builtins.anext
Ref: docs.python.org — builtins.bool
Tags: #public #python3 #stdlib #builtins
Import
import builtins
from builtins import bool
Signature & Overview
builtins.bool(object=False, /)
Returns True when the argument is true, False otherwise.
Methods & Attributes
bool.as_integer_ratio(self, /)— Return a pair of integers, whose ratio is equal to the original int.bool.bit_count(self, /)— Number of ones in the binary representation of the absolute value of self.bool.bit_length(self, /)— Number of bits necessary to represent self in binary.bool.conjugate(self, /)— Returns self, the complex conjugate of any int.bool.from_bytes(bytes, byteorder='big', *, signed=False)— Return the integer represented by the given array of bytes.bool.is_integer(self, /)— Returns True. Exists for duck type compatibility with float.is_integer.bool.to_bytes(self, /, length=1, byteorder='big', *, signed=False)— Return an array of bytes representing an integer.
Usage
assert bool(1) is True and bool(0) is False and bool([]) is False
assert isinstance(True, int) and True + True == 2
Gotchas
boolis a subclass ofint: Checkisinstance(x, bool)beforeisinstance(x, int)when type-dispatching.
REPL Inspect
from builtins import bool
help(bool)
Linked from
Related notes
- tuts/python3/stdlib_module/builtins/BlockingIOError Linked here; links to this page; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/breakpoint Linked here; links to this page; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/builtins/abs Linked here; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/aiter Linked here; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/all Linked here; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/anext Linked here; shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/any shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/ArithmeticError shared tags: #builtins, #stdlib
- tuts/python3/stdlib_module/builtins/ascii shared tags: #builtins, #stdlib