MicroPython Identity 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
* , **
Identity Operators
There are only two MicroPython identity operators. Though these identity operators won't often be used for simple project it is still useful to understand how they work. They provide a useful insight into how MicroPython creates objects (variables) and associates memory to these objects to hold data values.
Operator | Description |
---|---|
is[1] | Tests if two variables refer to the same object. x = ['cat', 'dog']
(x is y) ⇒ False
|
is not | Tests if two variables don't refer to the same object x = ['cat', 'dog']
(x is not y) ⇒ True
|
The above examples use Python lists. If the reader is not familiar with this data type then a tutorial can be found here