Boolean class¶
This page explains the Boolean
class.
Before reading on, maybe it is helpful to read the following page:
What is the Boolean class?¶
The Boolean
class is the apysc boolean class. It can accept bool
or Boolean
values at the constructor, as follows:
import apysc as ap
_ = ap.Stage()
bool_1: ap.Boolean = ap.Boolean(True)
assert bool_1
bool_2: ap.Boolean = ap.Boolean(False)
assert not bool_2
bool_3: ap.Boolean = ap.Boolean(bool_1)
assert bool_3
Note for the Bool class alias¶
The Bool
class is the alias of the Boolean
class. And it behaves the same as the Boolean
class.
import apysc as ap
_ = ap.Stage()
assert ap.Boolean == ap.Bool
assert ap.Boolean(True) == ap.Bool(True)
Boolean comparison¶
The Boolean
comparison interface behaves like the Python built-in bool
value.
You can compare it with the equal comparison operator (==
), and the Boolean
, bool
, int
, Int
types are acceptable, as follows:
import apysc as ap
_ = ap.Stage()
bool_1: ap.Boolean = ap.Boolean(True)
assert bool_1 == True # noqa
assert bool_1 == ap.Boolean(True)
assert bool_1 == 1
assert bool_1 == ap.Int(1)
Also, the not equal comparison operator (!=
) is supported, as follows:
import apysc as ap
_ = ap.Stage()
bool_1: ap.Boolean = ap.Boolean(True)
assert bool_1 != False # noqa
assert bool_1 != ap.Boolean(False)
assert bool_1 != 0
assert bool_1 != ap.Int(0)
You can skip the comparison operator, as follows:
import apysc as ap
_ = ap.Stage()
bool_1: ap.Boolean = ap.Boolean(True)
assert bool_1
bool_2: ap.Boolean = ap.Boolean(False)
assert not bool_2
Reverse a Boolean value¶
The not_
property returns the reversed Boolean
value:
import apysc as ap
_ = ap.Stage()
bool_1: ap.Boolean = ap.Boolean(True)
bool_2: ap.Boolean = bool_1.not_
assert not bool_2
bool_3: ap.Boolean = bool_2.not_
assert bool_3
Boolean class constructor API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface signature] __init__(self, value: Union[bool, typing_extensions.Literal[0, 1], apysc._type.int.Int, ForwardRef('Boolean')], *, variable_name_suffix: str = '', skip_init_substitution_expression_appending: bool = False) -> None
[Interface summary]
Boolean class for apysc library.
[Parameters]
value
: Boolean or Int or bool or intInitial boolean value. 0 or 1 are acceptable for an integer value.
variable_name_suffix
: str, default “”A JavaScript variable name suffix string. This setting is sometimes useful for JavaScript debugging.
skip_init_substitution_expression_appending
: bool, default FalseA boolean indicates whether to skip an initial substitution expression or not. This class uses this option internally.
[Notes]
The Bool class is the alias of the Boolean, and it behaves the same as the Boolean class.
[Examples]
>>> import apysc as ap
>>> _ = ap.Stage()
>>> bool_val_1: ap.Boolean = ap.Boolean(True)
>>> bool_val_1
Boolean(True)
>>> bool_val_2: ap.Bool = ap.Bool(True)
>>> bool_val_2
Boolean(True)
[References]
value property API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface summary]
Get a current boolean value.
[Returns]
value
: boolCurrent boolean value.
[Examples]
>>> import apysc as ap
>>> _ = ap.Stage()
>>> bool_val: ap.Boolean = ap.Boolean(True)
>>> bool_val.value = False
>>> bool_val.value
False
>>> bool_val.value = ap.Boolean(True)
>>> bool_val.value
True
[References]
not_ property API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface summary]
Get a not condition Boolean value.
[Returns]
result
: BooleanNot condition Boolean value.
[Examples]
>>> import apysc as ap
>>> _ = ap.Stage()
>>> bool_val: ap.Boolean = ap.Boolean(True)
>>> bool_val.not_
Boolean(False)
>>> bool_val.value = False
>>> bool_val.not_
Boolean(True)