MicroPython Membership 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
* , **
Membership Operations
Membership operators are used to test if a sequence is presented in an object. It is a simple concept that is best understood by following the examples in the table below.
Membership Operators
MicroPython provides two membership operators Both are useful and well worth understanding.
Operator | Description |
---|---|
in | Returns True if a sequence of the specified value is present in the object. x = ['apple', 'banana']
|
not in | Returns True if a sequence with the specified value is not present in the object. x = ['apple', 'banana']
|
The above examples use Python lists. If the reader is not familiar with this data type then a tutorial can be found here