108271 Views
83628 Views
56847 Views
48511 Views
47826 Views
47705 Views
Arduino Plug and Make Kit Review
Pi to Pico W Bluetooth Communication
Two-Way Bluetooth Communication Between Raspberry Pi Picos
Gamepad 2
Picotamachibi 2
Learning System updates
Introduction to the Linux Command Line on Raspberry Pi OS
How to install MicroPython
Wall Drawing Robot Tutorial
BrachioGraph Tutorial
Intermediate level MicroPython
Introduction to FreeCAD for Beginners
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 >