Operators
Operators
2
Python Arithmetic
Operators Arithmetic operators are used with numeric values to
perform common mathematical operations:
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
/ Division x/y
% Modulus x%y
** Exponentiation x ** y
Try
4
Python Assignment
Operators
Assignment operators are used to assign
values to variables:
Operator
=
Example
x=5
Same As
x=5
!
+= x += 3 x=x+3
-= x -= 3 x=x-3
*= x *= 3 x=x*3
/= x /= 3 x=x/3
%= x %= 3 x=x%3
//= x //= 3 x = x // 3
**= x **= 3 x = x ** 3
&= x &= 3 x=x&3
|= x |= 3 x=x|3
^= x ^= 3 x=x^3
>>= x >>= 3 x = x >> 3
<<= x <<= 3 x = x << 3
:= print(x := 3) x=3
print(x)
Python Comparison Operators
!= Not equal x != y
x=5
y=3
print(x == y)