For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
Bool
struct Bool
The primitive Bool scalar value used in Mojo.
Implemented traits
AnyType,
Boolable,
Comparable,
ConvertibleFromPython,
Copyable,
Defaultable,
Equatable,
Floatable,
Hashable,
ImplicitlyCopyable,
ImplicitlyDestructible,
Intable,
Movable,
RegisterPassable,
TrivialRegisterPassable,
Writable
comptime members
MAX
comptime MAX = True
The maximum value of a Bool.
MIN
comptime MIN = False
The minimum value of a Bool.
Methods
__init__
def __init__() -> Self
Construct a default, False Bool.
def __init__[T: Boolable, //](value: T) -> Self
Set the bool representation of the object.
Parameters:
- T (
Boolable): The type of the object.
Args:
- value (
T): The object to get the bool representation of.
def __init__(value: None) -> Self
Set the bool representation of the None type to False.
Args:
- value (
None): The object to get the bool representation of.
@implicit
def __init__(value: Scalar[DType.bool]) -> Self
Convert a scalar SIMD value to a Bool.
Args:
- value (
Scalar[DType.bool]): The scalar value.
__bool__
def __bool__(self) -> Self
Convert to Bool.
Returns:
Self: This value.
__invert__
def __invert__(self) -> Self
Inverts the Bool value.
Returns:
Self: True if the object is false and False otherwise.
__lt__
def __lt__(self, rhs: Self) -> Self
Compare this Bool to RHS using less-than comparison.
Args:
- rhs (
Self): The rhs of the operation.
Returns:
Self: True if self is False and rhs is True.
__le__
def __le__(self, rhs: Self) -> Self
Compare this Bool to RHS using less-than-or-equal comparison.
Args:
- rhs (
Self): The rhs of the operation.
Returns:
Self: True if self is False and rhs is True or False.
__eq__
def __eq__(self, rhs: Self) -> Self
Compare this Bool to RHS.
Performs an equality comparison between the Bool value and the argument.
This method gets invoked when a user uses the == infix operator.
Args:
- rhs (
Self): The rhs value of the equality statement.
Returns:
Self: True if the two values match and False otherwise.
__ne__
def __ne__(self, rhs: Self) -> Self
Compare this Bool to RHS.
Performs a non-equality comparison between the Bool value and the
argument. This method gets invoked when a user uses the != infix
operator.
Args:
- rhs (
Self): The rhs value of the non-equality statement.
Returns:
Self: False if the two values do match and True otherwise.
__gt__
def __gt__(self, rhs: Self) -> Self
Compare this Bool to RHS using greater-than comparison.
Args:
- rhs (
Self): The rhs of the operation.
Returns:
Self: True if self is True and rhs is False.
__ge__
def __ge__(self, rhs: Self) -> Self
Compare this Bool to RHS using greater-than-or-equal comparison.
Args:
- rhs (
Self): The rhs of the operation.
Returns:
Self: True if self is True and rhs is True or False.
__and__
def __and__(self, rhs: Self) -> Self
Returns self & rhs.
Bitwise and's the Bool value with the argument. This method gets invoked
when a user uses the and infix operator.
Args:
- rhs (
Self): The right hand side of theandstatement.
Returns:
Self: self & rhs.
__or__
def __or__(self, rhs: Self) -> Self
Returns self | rhs.
Bitwise or's the Bool value with the argument. This method gets invoked
when a user uses the or infix operator.
Args:
- rhs (
Self): The right hand side of theorstatement.
Returns:
Self: self | rhs.
__xor__
def __xor__(self, rhs: Self) -> Self
Returns self ^ rhs.
Bitwise Xor's the Bool value with the argument. This method gets invoked
when a user uses the ^ infix operator.
Args:
- rhs (
Self): The right hand side of thexorstatement.
Returns:
Self: self ^ rhs.
__rand__
def __rand__(self, lhs: Self) -> Self
Returns lhs & self.
Args:
- lhs (
Self): The left hand side of theandstatement.
Returns:
Self: lhs & self.
__ror__
def __ror__(self, lhs: Self) -> Self
Returns lhs | self.
Args:
- lhs (
Self): The left hand side of theorstatement.
Returns:
Self: lhs | self.
__rxor__
def __rxor__(self, lhs: Self) -> Self
Returns lhs ^ self.
Args:
- lhs (
Self): The left hand side of thexorstatement.
Returns:
Self: lhs ^ self.
__iand__
def __iand__(mut self, rhs: Self)
Computes self & rhs and store the result in self.
Args:
- rhs (
Self): The right hand side of theandstatement.
__ixor__
def __ixor__(mut self, rhs: Self)
Computes self ^ rhs and stores the result in self.
Args:
- rhs (
Self): The right hand side of thexorstatement.
__ior__
def __ior__(mut self, rhs: Self)
Computes self | rhs and store the result in self.
Args:
- rhs (
Self): The right hand side of theorstatement.
write_to
def write_to(self, mut writer: T)
Formats this boolean to the provided Writer.
Args:
- writer (
T): The object to write to.
write_repr_to
def write_repr_to(self, mut writer: T)
Writes the repr of this boolean to a writer.
The repr of a boolean is the same as its string representation:
True or False.
Args:
- writer (
T): The object to write to.
__int__
def __int__(self) -> Int
Convert this Bool to an integer.
Returns:
Int: 1 if the Bool is True, 0 otherwise.
__as_int__
def __as_int__(self) -> Int
Implicitly convert to an integral representation of the value, wherever an Int is expected.
Returns:
Int: The integral representation of the value.
__float__
def __float__(self) -> Float64
Convert this Bool to a float.
Returns:
Float64: 1.0 if True else 0.0 otherwise.
__hash__
def __hash__[H: Hasher](self, mut hasher: H)
Updates hasher with the underlying bytes.
Parameters:
- H (
Hasher): The hasher type.
Args:
- hasher (
H): The hasher instance.