Operators Flashcards
1
Q
+
A
Addition
…2 + 4 == 6
2
Q
-
A
Subtraction
…2 - 4 == -4
3
Q
*
A
Multiplication
…2 * 4 == 8
4
Q
**
A
Power of
…2 ** 4 == 16
5
Q
/
A
Division
…2 / 4 == 0.5
6
Q
//
A
Floor division
…2 // 4 == 0
7
Q
%
A
String interpolate or modulus
…2 % 4 == 2
8
Q
<
A
Less than
…4 < 4 == False
9
Q
>
A
Greater than
…4 > 4 == False
10
Q
<=
A
Less than or equal
…4 <= 4 == True
11
Q
> =
A
Greater than or equal to
…4 >= 4 == True
12
Q
==
A
Equal
…4 == 5 == False
13
Q
!=
A
Not equal
…4 != 5 == True
14
Q
( )
A
Parentheses
…len(‘hi’) == 2
15
Q
[ ]
A
List brackets
…[1, 3, 4]
16
Q
{ }
A
Dict curly braces
…{‘x’: 5, ‘y’: 10}
17
Q
@
A
At (decorators)
…@classmethod
18
Q
,
A
Comma
…range(0, 10)
19
Q
:
A
Colon
…def X(0):
20
Q
.
A
Dot
…self.x = 10
21
Q
=
A
Assign equal
…x = 10
22
Q
;
A
Semi-colon
…print(“hi”); print(“there”)
23
Q
+=
A
Add and assign
…x = 1; x += 2
24
Q
-=
A
Subtract and assign
…x = 1; x -=2
25
*=
Multiply and assign
…x = 1; x *= 2
26
/=
Divide and assign
…x = 1; x /= 2
27
//=
Floor divide and assign
…x - 1; x //= 2
28
%=
Modulus assign
…x = 1; x %= 2
29
**=
Power assign
…x = 1; x **= 2