+
: adds two numbers, and concatenates strings
and lists.
1 + 2
, "Hello " + "world!"
, [1] + [2]
-
: subtracts two numbers, and does
set difference with sets.
1 - 2
, {1, 2, 3} - {2, 3, 4}
*
: multiplies two numbers, repeats strings,
and lists.
1 * 2
, "Hello " * 3
, [1] * 2
/
: divides two numbers.
12 / 4
**
: raises a number to a power.
10 ** 2
//
: divides two numbers and rounds down.
10 // 3
%
: divides two numbers and returns the remainder.
10 % 3
+=
adds a number to a variable.
i += 1
==
: checks if two values are equal.
1 == 2
, "Hello" == "Hello"
<
, >
,
<=
, and >=
: checks if two values are less than,
greater than, less than or equal to, or greater than or equal to each other;
does set subset and superset with sets.
1 < 2
, 1 > 2
,
1 <= 2
, 1 >= 2
,
{1, 2} < {1, 2, 3}
and
, &
: checks if two boolean
values are both true, does set intersection with sets.
True and False
, {1, 2, 3} & {2, 4, 6}
or
, |
: checks if at least one of two
boolean values are true, does set union with sets.
True or False
, {1, 2, 3} | {2, 4, 6}
xor
, ^
: checks if exactly one of two
boolean values are true, does set symmetric difference with sets.
True ^ False
, {1, 2, 3} ^ {2, 4, 6}
not
, !=
: checks if a boolean value is
false, check if two values are not equal.
not True
, 1 != 2
Feel free to copy any of the examples into the empty code
editor below. You will need to wrap the code in a
print
function for it to display.