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