100751 Views
79190 Views
45286 Views
43314 Views
39973 Views
33349 Views
NextCloud
Buddy Jr.
Robot Arms
TherePi - Music Making with a Raspberry Pi
Motion Controlled Arm
Electric Trombone
Building a Robot Arm with Raspberry Pi and PCA9685
Building User Authentication for Static Sites with FastAPI
Mastering Pydantic for Robust Data Validation
Mastering Markdown for Documentation with Jekyll
Introduction to Rust
OctaPi
KevsRobots Learning Platform
80% Percent Complete
By Kevin McAleer, 8 Minutes
Operators are the symbols such as + and -.
+
-
There are many types of operators, and we use them to do things like add numbers together, compare numbers and variables, and do some more advanced things that python is good at, like managing sets. Weāll look at those in later tutorials.
sets
Here is a list of all the operators available. Donāt worry if this is overwhelming, you donāt need to know many, and you probably already know a few of the arithmetic ones.
Have a look through these, but donāt worry, there isnāt a test!
Here are the shortcut links to each of the types of Operators defined below:
Arithmetic Operators Comparison (Relational) Operators Assignment Operators Logical Operators Bitwise Operators Membership Operators Identity Operators
In the examples below a = 10, b = 20.
a
10
b
20
Table of MicroPython Arithmetic Operators
a + b = 30
a ā b = -10
*
a * b = 200
/
b / a = 2.0
%
b % a = 0
**
a**b =10
//
9//2 = 4
9.0//2.0 = 4.0
-11//3 = -4
-11.0//3 = -4.0
Table of MicroPython Comparitive Operators
==
(a == b)
!=
(a != b)
<>
(a <> b)
>
(a > b)
<
(a < b)
>=
(a >= b)
<=
(a <= b)
Table of MicroPython Assignment Operators
=
a = 10
+=
c += a
c = c + a
-=
c -= a
c = c - a
*=
c *= a
c = c * a
/=
c /= a
c = c / a
%=
c %= a
c = c % a
**=
c **= a
c = c ** a
//=
c //= a
c = c // a
Table of MicroPython Logical Operators
and
(a and b)
or
(a or b)
not
not(a and b)
In the examples below a = 60, b = 13.
60
13
Table of MicroPython Bitwise Operators
&
(a & b) = 12
|
(a | b) = 61
^
(a ^ b) = 49
~
(~a ) = -61
<<
a << 2 = 240
>>
a >> 2 = 15
Table of MicroPython Membership Operators
in
x in y
not in
x not in y
Table of MicroPython Identity Operators
is
x is y
is not
x is not y
< Previous Next >