Skip to content
On this page

Booleans

The type sp.bool has two literals: True and False.

The expression a and b is True if and only if both a and b are True. The expression a or b is True if and only if at least one of a and b is True. The expression a ^ b is True if and only if exactly one of a and b is True.

Note that and and or do "short-circuiting": for a or b, if a == True then b is not evaluated. For a and b, if a == False then b is not evaluated.

For example, this statement runs successfully:

smartpy
assert True or 1 / 0 == 42

On the other hand, the following statement raises a division-by-zero error:

smartpy
assert 1 / 0 == 42 or True

Note that these operations work on booleans only. For bitwise operations on integers, see bitwise arithmetic.