105800 Views
82496 Views
47243 Views
47066 Views
45458 Views
38527 Views
Pi-Apps
Intermediate MicroPython
Arduino Alvik
Raspberry Pi Time machine
Now Ad-Free
Guiding Light
Intermediate level MicroPython
Introduction to FreeCAD for Beginners
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
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 >