MicroPython Arithmetic 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
* , **
Arithmetic Operators
All seven arithmetic operators available in Python are also found in MicroPython.
Op | Name | Example |
---|---|---|
- | Subtraction[1] | (12 - 5) ⇒ 7 |
+ | Addition | (7 + 3) ⇒ 10 |
* | Multiplication | (7 * 3) ⇒ 21 |
/ | Division[2] | (7 / 3) ⇒ 2.333333 |
% | Modulus | Returns the remainder of a division
(7 % 3) ⇒ 1
|
** | Exponentiation | (7 ** 3) ⇒ 343
7 * 7 * 7 ⇒ 343 Alternative:
|
// | Floor Division[3] | (7 // 3) ⇒ 2
(-7 // 3) ⇒ -3 (-7 // -3) ⇒ 2 |