The unofficial CircuitPython Reference

boolean

description

Python has 5 primitive classes of data: string, integer, float, boolean, and complex. There is no need to declare a specific data type for variable as Python will infer the data type at assignment.

The boolean type stores True and False values and is the result of comparison operations and logical operations. Declaring a boolean variable requires a variable name, followed by an assignment operator followed by either True or False.

When declaring a variable in Python it must begin with a letter and the name may only contain letters, numbers, and underscores. For the sake of readability it is conventional to use all lower case letters and numbers for variable names with underscores to separate words. It is best to avoid I and O for single letter variable names as they can look like 1 and 0. Python does not have a constant keyword and there is therefore no enforced constant but again for readability it is conventional to name CONSTANTS with all caps and underscores between words.

syntax

declare a boolean (implicit)

my_bool = True

declare multiple boolean

bool1, bool2, bool3 = False, True, False

methods

parameters

returns

example code

serial output:

code.py output:

True

False

True

False

see also: