MicroPython Comparison and Logical Operators
Contents
Introduction
Operators are an essential part of just about any computing language ever devised and MicroPython is of no exception. The MicroPython operators can be broadly classified into eight groups:
- Arithmetic
- , + , * , / , % , ** , // - Assignment
= , augmented assignments e.g. += - Comparison
== , != , > , < , >= , <= - Logical
and , or , not - Identity
is , is not - Membership
in , not in - Bitwise
& , ! , ^ , ~ , << , >> - Unpacking Operators
* , **
Comparison Operators
All six comparison operators available in Python are also found in MicroPython.
Operator | Description |
---|---|
== | Equal x, y = 5, 5
|
!= | Not Equal x, y = 5, 5
|
> | Greater Than x, y = 6, 5
|
< | Less Than x, y = 6, 5
|
>= | Greater Than or Equal To x, y = 6, 5
x, y = 6, 6
|
<= | Less Than or Equal To x, y = 6, 5
x, y = 6, 6
|
Logical Operators
Logical operators are used to combine conditional statements containing comparison operators. MicroPython has only three logical operators.
Operator | Description |
---|---|
and | (Statement 1) and (statement 2) x, y = 5, 6
|
or | (Statement 1) or (statement 2) x, y = 5, 6
|
not | Reverses the result;
x, y = 5, 6
|